[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Feed API: WP_Feed_Cache_Transient class 4 * 5 * @package WordPress 6 * @subpackage Feed 7 * @since 4.7.0 8 */ 9 10 /** 11 * Core class used to implement feed cache transients. 12 * 13 * @since 2.8.0 14 */ 15 class WP_Feed_Cache_Transient { 16 17 /** 18 * Holds the transient name. 19 * 20 * @since 2.8.0 21 * @var string 22 */ 23 public $name; 24 25 /** 26 * Holds the transient mod name. 27 * 28 * @since 2.8.0 29 * @var string 30 */ 31 public $mod_name; 32 33 /** 34 * Holds the cache duration in seconds. 35 * 36 * Defaults to 43200 seconds (12 hours). 37 * 38 * @since 2.8.0 39 * @var int 40 */ 41 public $lifetime = 43200; 42 43 /** 44 * Constructor. 45 * 46 * @since 2.8.0 47 * @since 3.2.0 Updated to use a PHP5 constructor. 48 * 49 * @param string $location URL location (scheme is used to determine handler). 50 * @param string $filename Unique identifier for cache object. 51 * @param string $extension 'spi' or 'spc'. 52 */ 53 public function __construct( $location, $filename, $extension ) { 54 $this->name = 'feed_' . $filename; 55 $this->mod_name = 'feed_mod_' . $filename; 56 57 $lifetime = $this->lifetime; 58 /** 59 * Filters the transient lifetime of the feed cache. 60 * 61 * @since 2.8.0 62 * 63 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). 64 * @param string $filename Unique identifier for the cache object. 65 */ 66 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename ); 67 } 68 69 /** 70 * Sets the transient. 71 * 72 * @since 2.8.0 73 * 74 * @param SimplePie $data Data to save. 75 * @return true Always true. 76 */ 77 public function save( $data ) { 78 if ( $data instanceof SimplePie ) { 79 $data = $data->data; 80 } 81 82 set_transient( $this->name, $data, $this->lifetime ); 83 set_transient( $this->mod_name, time(), $this->lifetime ); 84 return true; 85 } 86 87 /** 88 * Gets the transient. 89 * 90 * @since 2.8.0 91 * 92 * @return mixed Transient value. 93 */ 94 public function load() { 95 return get_transient( $this->name ); 96 } 97 98 /** 99 * Gets mod transient. 100 * 101 * @since 2.8.0 102 * 103 * @return mixed Transient value. 104 */ 105 public function mtime() { 106 return get_transient( $this->mod_name ); 107 } 108 109 /** 110 * Sets mod transient. 111 * 112 * @since 2.8.0 113 * 114 * @return bool False if value was not set and true if value was set. 115 */ 116 public function touch() { 117 return set_transient( $this->mod_name, time(), $this->lifetime ); 118 } 119 120 /** 121 * Deletes transients. 122 * 123 * @since 2.8.0 124 * 125 * @return true Always true. 126 */ 127 public function unlink() { 128 delete_transient( $this->name ); 129 delete_transient( $this->mod_name ); 130 return true; 131 } 132 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |