SimplePie_Cache_File

Caches data to the filesystem.

Defined (1)

The class is defined in the following location(s).

/wp-includes/SimplePie/Cache/File.php  
  1. class SimplePie_Cache_File implements SimplePie_Cache_Base 
  2. /** 
  3. * Location string 
  4. * @see SimplePie::$cache_location 
  5. * @var string 
  6. */ 
  7. protected $location; 
  8.  
  9. /** 
  10. * Filename 
  11. * @var string 
  12. */ 
  13. protected $filename; 
  14.  
  15. /** 
  16. * File extension 
  17. * @var string 
  18. */ 
  19. protected $extension; 
  20.  
  21. /** 
  22. * File path 
  23. * @var string 
  24. */ 
  25. protected $name; 
  26.  
  27. /** 
  28. * Create a new cache object 
  29. * @param string $location Location string (from SimplePie::$cache_location) 
  30. * @param string $name Unique ID for the cache 
  31. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 
  32. */ 
  33. public function __construct($location, $name, $type) 
  34. $this->location = $location; 
  35. $this->filename = $name; 
  36. $this->extension = $type; 
  37. $this->name = "$this->location/$this->filename.$this->extension"; 
  38.  
  39. /** 
  40. * Save data to the cache 
  41. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 
  42. * @return bool Successfulness 
  43. */ 
  44. public function save($data) 
  45. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) 
  46. if ($data instanceof SimplePie) 
  47. $data = $data->data; 
  48.  
  49. $data = serialize($data); 
  50. return (bool) file_put_contents($this->name, $data); 
  51. return false; 
  52.  
  53. /** 
  54. * Retrieve the data saved to the cache 
  55. * @return array Data for SimplePie::$data 
  56. */ 
  57. public function load() 
  58. if (file_exists($this->name) && is_readable($this->name)) 
  59. return unserialize(file_get_contents($this->name)); 
  60. return false; 
  61.  
  62. /** 
  63. * Retrieve the last modified time for the cache 
  64. * @return int Timestamp 
  65. */ 
  66. public function mtime() 
  67. if (file_exists($this->name)) 
  68. return filemtime($this->name); 
  69. return false; 
  70.  
  71. /** 
  72. * Set the last modified time to the current time 
  73. * @return bool Success status 
  74. */ 
  75. public function touch() 
  76. if (file_exists($this->name)) 
  77. return touch($this->name); 
  78. return false; 
  79.  
  80. /** 
  81. * Remove the cache 
  82. * @return bool Success status 
  83. */ 
  84. public function unlink() 
  85. if (file_exists($this->name)) 
  86. return unlink($this->name); 
  87. return false;