* array( * 'ttl' => 60*60*24, // 24hrs Time-To-Life * ); * * * @var array */ protected $options = array( 'ttl' => 86400, // 60*60*24 == 24hrs 'extension' => '.cache', ); /** * Creates a new cache storage in the given location. * Creates a new cache storage for a given location. The location can * differ for each ezcCacheStorage implementation, but will most likely * be a filesystem path to a directory where cache data is stored in. * * Per default there is only 1 common option for all ezcCacheStorage * classes, which is the 'ttl' ( Time-To-Life ). This is per default set * to 1 day. Specific ezcCacheStorage implementations can have * additional options. * * @param string $location Path to the cache location * @param array(string) $options Options * * @throws ezcCacheStorageException * If the storage location does not exist * {@link ezcCacheStorageException::LOCATION_NOT_AVAILABLE}. * @throws ezcCacheStorageException * If the storage location is not a directory * {@link ezcCacheStorageException::LOCATION_NOT_AVAILABLE}. * @throws ezcCacheStorageException * If the storage location is not writeable * {@link ezcCacheStorageException::LOCATION_NOT_WRITEABLE}. * @throws ezcBaseConfigException * If an unknown option is set * {@link ezcBaseConfigException::UNKNOWN_CONFIG_SETTING}. */ public function __construct( $location, $options = null ) { $this->location = ( substr( $location, -1 ) === '/' ) ? $location : $location . '/'; $this->validateLocation(); $this->setOptions( $options ); } /** * Store data to the cache storage. * This methode stores the given cache data into the cache, assigning the * ID given to it. * * The type of cache data which is expected by a ezcCacheStorage depends on * it's implementation. In most cases strings and arrays will be accepted, * in some rare cases only strings might be accepted. * * Using attributes you can describe your cache data further. This allows * you to deal with multiple cache data at once later. Some ezcCacheStorage * implementations also use the attributes for storage purposes. Attributes * form some kind of "extended ID". * * @param string $id The unique identifier for the data stored. * @param mixed $data The data to store. * @param array $attributes Attributes that describe the cached data. * * @return string The ID of the newly cached data. * * @throws ezcCacheStorageException * If the location is not writeable * {@link ezcCacheStorageException::LOCATION_NOT_WRITABLE}. * @throws ezcCacheStorageException * If the data could not be written to the location * {@link ezcCacheStorageException::LOCATION_NOT_AVAILABLE}. * @throws ezcCacheStorageException * If the data submitted is an object or a resource * {@link ezcCacheStorageException::DATA_INVALID}. */ abstract public function store( $id, $data, $attributes = array() ); /** * Restore data from the cache. * Restores the data associated with the given cache and * returns it. Please see {@link ezcCacheStorage::store()} * for more detailed information of cachable datatypes. * * During access to cached data the caches are automatically * expired. This means, that the ezcCacheStorage object checks * before returning the data if it's still actual. If the cache * has expired, data will be deleted and false is returned. * * You should always provide the attributes you assigned, although * the cache storages must be able to find a cache ID even without * them. BEWARE: Finding cache data only by ID can be much * slower than finding it by ID and attributes. * * @param string $id The cache ID to restore data from. * @param array $attributes Attributed describing the data to restore. * * @return mixed The cached data on success, otherwise false. */ abstract public function restore( $id, $attributes = array() ); /** * Delete data from the cache. * Purges the cached data for a given ID and or attributes. Using an ID * purges only the cache data for just this ID. * * Additional attributes provided will matched additionally. This can give * you an immense speed improvement against just searching for ID ( see * {@link ezcCacheStorage::restore()} ). * * If you only provide attributes for deletion of cache data, all cache * data matching these attributes will be purged. * * @param string $id The ID of the data to purge. * @param array $attributes Attributes describing the data to purge. * * @throws ezcCacheStorageException * If the location is not writeable * {@link ezcCacheStorageException::LOCATION_NOT_WRITABLE}. */ abstract public function delete( $id = null, $attributes = array() ); /** * Return the number of items in the cache matching a certain criteria. * This method determines if cache data described by the given ID and/or * attributes exists. It returns the number of cache data items found. * * @param string $id The ID of the cache data. * @param array $attributes Attributes to describe the data. * @return int The number of cache data items found matching the criteria. */ abstract public function countDataItems( $id = null, $attributes = array() ); /** * Returns the time ( in seconds ) which remains for a cache objes, * before it gets outdated. In case the cache object is already * outdated or does not exists, this method returns 0. * * @param string $id The ID of the cache data. * @param array $attributes Attributes to describe the data. * @access public * @return int The remaining lifetime ( 0 if nonexists or oudated ). */ abstract public function getRemainingLifetime( $id, $attributes = array() ); /** * Returns the location. * Returns the location the current storage resides in. The * $location attribute has no setter, since it can only be set during * construction. * * @return string The location of this storage. */ public function getLocation() { return $this->location; } /** * Return the currently set options. * Return the currently set options. * * @return array The options */ public function getOptions() { return $this->options; } /** * Set new options. * * @param array $options The options * * @throws ezcBaseConfigException * If the desired option does not exist * {@link ezcBaseConfigException::UNKNOWN_CONFIG_SETTING}. */ public function setOptions( $options = null ) { if ( !is_array( $options ) ) { return; } foreach ( $options as $name => $val ) { if ( isset( $this->options[$name] ) ) { $this->options[$name] = $val; } else { throw new ezcBaseConfigException( $name, ezcBaseConfigException::UNKNOWN_CONFIG_SETTING ); } } } } ?>