Class Picasa_Cache

Description

A simple chaching mechanism to reduce the number of calls made to the Picasa service.

This is an easy way to cache into flat files the XML feed returned by Picasa for many API calls. This class uses the Singleton pattern so that caching can be turned on once for the client's entire application.

  • author: Cameron Hinkle
  • version: Version 1.0
  • copyright: Copyright (c) 2007 Cameron Hinkle
  • since: Version 3.3
  • license: GNU Public License Version 3

Located in /Picasa/Cache.php (line 18)


	
			
Variable Summary
static string $DEFAULT_CACHE_PATH
integer $cacheExpire
string $cachePath
boolean $enabled
Method Summary
Picasa_Cache __construct ([boolean $enabled = false])
string cacheGet (string $key)
boolean clear ([string $pathname = null])
boolean existsInCache (string $key)
string getCacheExpire ()
string getCacheKey ( $feedName, string $feedname)
string getCachePath ()
The getIfCached (string $feedUrl)
boolean isCached (string $feedUrl)
boolean isEnabled ()
boolean isExpired (string $key)
void setCacheExpire (string $cacheExpire)
void setCachePath ( $cachePath, string $cacheExpire)
void setEnabled ([boolean $enabled = true])
boolean setInCache (string $filename, string $contents)
Variables
static int $DEFAULT_CACHE_EXPIRE = 7200 (line 29)

Default number of seconds a file will remain cached before it is refreshed.

The value out of the box is 7200 (2 hours). If you do not want to set it manually in your client application, feel free to change it here.

  • see: function setCacheExpire()
  • access: private
static string $DEFAULT_CACHE_PATH = 'picasa_api_cache' (line 43)

Default location on your server's file system that cache files are stored.

Actually, this location is appended to PHP's include path. This is done by default so a location is chosen that PHP definitely has access to. You can change this is the class's constructor. It is highly recommended that you change this to whatever you want it to be if you do not want the out of the box value because it is risky to change it within your client code.

This path must be readable and writeable by php or caching will be disabled automatically.

  • access: private
static Picasa_Cache $instance = null (line 51)

The caching instance, used for the Singleton pattern.

  • access: private
integer $cacheExpire (line 78)

The number of seconds after any file is cached that it should be refreshed. If a cache key is accessed this number of seconds after it is initially set, the caching mechanism behaves as though it is not cached.

  • access: private
string $cachePath (line 68)

The absolute path to store the cache files. PHP must have write access to this path or caching will be turned off.

  • access: private
boolean $enabled (line 59)

Flag to determine whether or not to cache files.

  • access: private
Methods
static method getCache (line 148)

Public method to get a Cache instance. This is to ensure that only one instance is ever created.

  • return: The Cache instance.
  • access: public
static Picasa_Cache getCache ()
Constructor __construct (line 120)

Constructs a Cache object. Declared as private for Singleton pattern so there is only one instance.

  • access: private
Picasa_Cache __construct ([boolean $enabled = false])
  • boolean $enabled: Determines whether or not to cache.
cacheGet (line 292)

Gets the contents at the specified cache key. It will throw an error if the key is not in the cache. It will also return the contents if the cache key has expired. The existence and validity of the key needs to be checked before calling this.

  • return: The value at the specified cache key.
  • access: private
string cacheGet (string $key)
  • string $key: The cache key to get the contents of.
clear (line 215)

Clears the cache. If a path is supplied, just clears the key mapping to that path. Otherwise, clears the entire cache.

  • return: true if it successfully clears the requested part of the cache, false otherwise.
  • access: public
boolean clear ([string $pathname = null])
  • string $pathname: The URL of the XML feed to clear from the cache. If none is supplied, the entire cache is cleared.
existsInCache (line 334)

Checks the mere existance (not expiration) of a cache key.

  • return: true if the cache key exists, false otherwise.
  • access: private
boolean existsInCache (string $key)
  • string $key: The cache key to check the existance of.
getCacheExpire (line 84)
  • access: public
string getCacheExpire ()
getCacheKey (line 303)

Converts the URL to the feed to cache into a cache key.

  • return: The valid cache key.
  • access: private
string getCacheKey ( $feedName, string $feedname)
  • string $feedname: The URL to convert into a cache key.
  • $feedName
getCachePath (line 92)
  • access: public
string getCachePath ()
getIfCached (line 250)

Gets the requested feed from the cache if it exists. If it doesn't, returns false.

  • return: contents of the cached URL if the feed was cached. false otherwise.
  • access: public
The getIfCached (string $feedUrl)
  • string $feedUrl: The URL of the XML feed to fetch from the cache.
isCached (line 198)

Checks if the feed passed in is already cached.

  • return: true if the feed is cached and the cache key hasn't expired, false otherwise.
  • access: public
boolean isCached (string $feedUrl)
  • string $feedUrl: The URL of the XML feed to cache. Not the cache key itself.
isEnabled (line 178)

Just checks the value of the enabled flag. Could be true or false.

  • return: The value of the enabled flag or false if it's not set.
  • access: public
boolean isEnabled ()
isExpired (line 317)

Checks if a cache key has expired.

boolean isExpired (string $key)
  • string $key: The cache key to check the validity of.
setCacheExpire (line 101)
  • access: public
void setCacheExpire (string $cacheExpire)
  • string $cacheExpire
setCachePath (line 110)
  • access: public
void setCachePath ( $cachePath, string $cacheExpire)
  • string $cacheExpire
  • $cachePath
setEnabled (line 162)

Sets the flag that determines whether or not to cache.

  • access: public
void setEnabled ([boolean $enabled = true])
  • boolean $enabled: The value to set the enabled flag to. true will cause xml feeds to be cached, false will cause xml feeds to always be downloaded fresh. The default is true.
setInCache (line 271)

Caches the contents of a file.

  • return: true if the content was successfully cached, false otherwise.
  • access: public
boolean setInCache (string $filename, string $contents)
  • string $filename: The full path of the contents being cached.
  • string $contents: The contents to cache.

Documentation generated on Tue, 02 Jun 2009 14:51:50 -0700 by phpDocumentor 1.4.1