Title: RSSCache
Published: April 25, 2014
Last modified: February 24, 2026

---

# class RSSCache {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/rsscache/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/rsscache/?output_format=md#source)

[ Back to top](https://developer.wordpress.org/reference/classes/rsscache/?output_format=md#wp--skip-link--target)

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/rsscache/?output_format=md#methods)󠁿

| Name | Description | 
| [RSSCache::__construct](https://developer.wordpress.org/reference/classes/rsscache/__construct/) | PHP5 constructor. | 
| [RSSCache::check_cache](https://developer.wordpress.org/reference/classes/rsscache/check_cache/) | – | 
| [RSSCache::debug](https://developer.wordpress.org/reference/classes/rsscache/debug/) | – | 
| [RSSCache::error](https://developer.wordpress.org/reference/classes/rsscache/error/) | – | 
| [RSSCache::file_name](https://developer.wordpress.org/reference/classes/rsscache/file_name/) | – | 
| [RSSCache::get](https://developer.wordpress.org/reference/classes/rsscache/get/) | – | 
| [RSSCache::RSSCache](https://developer.wordpress.org/reference/classes/rsscache/rsscache/) | PHP4 constructor. | 
| [RSSCache::serialize](https://developer.wordpress.org/reference/classes/rsscache/serialize/) | – | 
| [RSSCache::set](https://developer.wordpress.org/reference/classes/rsscache/set/) | – | 
| [RSSCache::unserialize](https://developer.wordpress.org/reference/classes/rsscache/unserialize/) | – |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/rsscache/?output_format=md#source)󠁿

    ```php
    class RSSCache {
    	var $BASE_CACHE;	// where the cache files are stored
    	var $MAX_AGE	= 43200;  		// when are files stale, default twelve hours
    	var $ERROR 		= '';			// accumulate error messages

    	/**
    	 * PHP5 constructor.
    	 */
    	function __construct( $base = '', $age = '' ) {
    		$this->BASE_CACHE = WP_CONTENT_DIR . '/cache';
    		if ( $base ) {
    			$this->BASE_CACHE = $base;
    		}
    		if ( $age ) {
    			$this->MAX_AGE = $age;
    		}

    	}

    	/**
    	 * PHP4 constructor.
    	 */
    	public function RSSCache( $base = '', $age = '' ) {
    		self::__construct( $base, $age );
    	}

    /*=======================================================================*\
    	Function:	set
    	Purpose:	add an item to the cache, keyed on url
    	Input:		url from which the rss file was fetched
    	Output:		true on success
    \*=======================================================================*/
    	function set ($url, $rss) {
    		$cache_option = 'rss_' . $this->file_name( $url );

    		set_transient($cache_option, $rss, $this->MAX_AGE);

    		return $cache_option;
    	}

    /*=======================================================================*\
    	Function:	get
    	Purpose:	fetch an item from the cache
    	Input:		url from which the rss file was fetched
    	Output:		cached object on HIT, false on MISS
    \*=======================================================================*/
    	function get ($url) {
    		$this->ERROR = "";
    		$cache_option = 'rss_' . $this->file_name( $url );

    		if ( ! $rss = get_transient( $cache_option ) ) {
    			$this->debug(
    				"Cache does not contain: $url (cache option: $cache_option)"
    			);
    			return 0;
    		}

    		return $rss;
    	}

    /*=======================================================================*\
    	Function:	check_cache
    	Purpose:	check a url for membership in the cache
    				and whether the object is older then MAX_AGE (ie. STALE)
    	Input:		url from which the rss file was fetched
    	Output:		cached object on HIT, false on MISS
    \*=======================================================================*/
    	function check_cache ( $url ) {
    		$this->ERROR = "";
    		$cache_option = 'rss_' . $this->file_name( $url );

    		if ( get_transient($cache_option) ) {
    			// object exists and is current
    				return 'HIT';
    		} else {
    			// object does not exist
    			return 'MISS';
    		}
    	}

    /*=======================================================================*\
    	Function:	serialize
    \*=======================================================================*/
    	function serialize ( $rss ) {
    		return serialize( $rss );
    	}

    /*=======================================================================*\
    	Function:	unserialize
    \*=======================================================================*/
    	function unserialize ( $data ) {
    		return unserialize( $data );
    	}

    /*=======================================================================*\
    	Function:	file_name
    	Purpose:	map url to location in cache
    	Input:		url from which the rss file was fetched
    	Output:		a file name
    \*=======================================================================*/
    	function file_name ($url) {
    		return md5( $url );
    	}

    /*=======================================================================*\
    	Function:	error
    	Purpose:	register error
    \*=======================================================================*/
    	function error ($errormsg, $lvl=E_USER_WARNING) {
    		$this->ERROR = $errormsg;
    		if ( MAGPIE_DEBUG ) {
    			wp_trigger_error( '', $errormsg, $lvl);
    		}
    		else {
    			error_log( $errormsg, 0);
    		}
    	}
    			function debug ($debugmsg, $lvl=E_USER_NOTICE) {
    		if ( MAGPIE_DEBUG ) {
    			$this->error("MagpieRSS [debug] $debugmsg", $lvl);
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rss.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rss.php#L718)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rss.php#L718-L840)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Frsscache%2F)
before being able to contribute a note or feedback.