WP_Feed_Cache_Transient

Core class used to implement feed cache transients.

Defined (1)

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

/wp-includes/class-wp-feed-cache-transient.php  
  1. class WP_Feed_Cache_Transient { 
  2.  
  3. /** 
  4. * Holds the transient name. 
  5. * @since 2.8.0 
  6. * @access public 
  7. * @var string 
  8. */ 
  9. public $name; 
  10.  
  11. /** 
  12. * Holds the transient mod name. 
  13. * @since 2.8.0 
  14. * @access public 
  15. * @var string 
  16. */ 
  17. public $mod_name; 
  18.  
  19. /** 
  20. * Holds the cache duration in seconds. 
  21. * Defaults to 43200 seconds (12 hours). 
  22. * @since 2.8.0 
  23. * @access public 
  24. * @var int 
  25. */ 
  26. public $lifetime = 43200; 
  27.  
  28. /** 
  29. * Constructor. 
  30. * @since 2.8.0 
  31. * @since 3.2.0 Updated to use a PHP5 constructor. 
  32. * @access public 
  33. * @param string $location URL location (scheme is used to determine handler). 
  34. * @param string $filename Unique identifier for cache object. 
  35. * @param string $extension 'spi' or 'spc'. 
  36. */ 
  37. public function __construct($location, $filename, $extension) { 
  38. $this->name = 'feed_' . $filename; 
  39. $this->mod_name = 'feed_mod_' . $filename; 
  40.  
  41. $lifetime = $this->lifetime; 
  42. /** 
  43. * Filters the transient lifetime of the feed cache. 
  44. * @since 2.8.0 
  45. * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). 
  46. * @param string $filename Unique identifier for the cache object. 
  47. */ 
  48. $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename); 
  49.  
  50. /** 
  51. * Sets the transient. 
  52. * @since 2.8.0 
  53. * @access public 
  54. * @param SimplePie $data Data to save. 
  55. * @return true Always true. 
  56. */ 
  57. public function save($data) { 
  58. if ( $data instanceof SimplePie ) { 
  59. $data = $data->data; 
  60.  
  61. set_transient($this->name, $data, $this->lifetime); 
  62. set_transient($this->mod_name, time(), $this->lifetime); 
  63. return true; 
  64.  
  65. /** 
  66. * Gets the transient. 
  67. * @since 2.8.0 
  68. * @access public 
  69. * @return mixed Transient value. 
  70. */ 
  71. public function load() { 
  72. return get_transient($this->name); 
  73.  
  74. /** 
  75. * Gets mod transient. 
  76. * @since 2.8.0 
  77. * @access public 
  78. * @return mixed Transient value. 
  79. */ 
  80. public function mtime() { 
  81. return get_transient($this->mod_name); 
  82.  
  83. /** 
  84. * Sets mod transient. 
  85. * @since 2.8.0 
  86. * @access public 
  87. * @return bool False if value was not set and true if value was set. 
  88. */ 
  89. public function touch() { 
  90. return set_transient($this->mod_name, time(), $this->lifetime); 
  91.  
  92. /** 
  93. * Deletes transients. 
  94. * @since 2.8.0 
  95. * @access public 
  96. * @return true Always true. 
  97. */ 
  98. public function unlink() { 
  99. delete_transient($this->name); 
  100. delete_transient($this->mod_name); 
  101. return true;