Overview

File-based cache controller.

This is the file-based adapter for [Solar_Cache:HomePage Solar_Cache]. In general, you never need to instantiate it yourself; instead, use Solar_Cache as the frontend for it and specify 'Solar_Cache_File' as the 'adapter' config key value.

If you specify a path (for storing cache entry files) that does not exist, this adapter attempts to create it for you.

This adapter always uses » flock() when reading and writing cache entries; it uses a shared lock for reading, and an exclusive lock for writing. This is to help cut down on cache corruption when two processes are trying to access the same cache file entry, one for reading and one for writing.

In addition, this adapter automatically serializes and unserializes arrays and objects that are stored in the cache. This means you can store not only string output, but also array data and entire objects in the cache ... just like Solar_Cache_Memcache.

Package

This class is part of the Solar_Cache package.

Inheritance:

Configuration Keys

  • active: Whether or not the cache should be active at instantiation.

  • life: The lifetime of each cache entry in seconds.

  • prefix: A prefix to place in front of every cache entry key; e.g., use this to deconflict between identical cache keys in caches shared among different domains or environments.

  • path: The directory where cache files are located; should be readable and writable by the script process, usually the web server process. Default is '/Solar_Cache_File' in the system temporary directory. Will be created if it does not already exist. Supports streams, so you may specify (e.g.) 'http://cache-server/' as the path.

  • mode: If the cache path does not exist, when it is created, use this octal permission mode. Default is 0740 (user read/write/exec, group read, others excluded).

  • context: A stream context resource, or an array to pass to stream_create_context(). When empty, no context is used. Default null.

  • hash: Whether or not to hash the cache entry filenames.

Constants

None.

Public Properties

The Solar_Cache_Adapter_File class has no public properties; try the list of all properties.

Public Methods

These are all the public methods in the Solar_Cache_Adapter_File class.

You can also view the list of all public, protected, and private methods.

__construct()

Constructor.

__destruct()

Default destructor; does nothing other than provide a safe fallback for calls to parent::__destruct().

add()

Inserts cache entry data, but only if the entry does not already exist.

delete()

Deletes an entry from the cache.

deleteAll()

Removes all entries from the cache.

dump()

Convenience method for getting a dump the whole object, or one of its properties, or an external variable.

entry()

Returns the path and filename for the entry key.

fetch()

Fetches cache entry data.

fetchOrAdd()

Fetches data if it exists; if not, uses a callback to create the data and adds it to the cache in a race-condition-safe way.

fetchOrSave()

Fetches data if it exists; if not, uses a callback to create the data and saves it to the cache.

getLife()

Gets the cache lifetime in seconds.

increment()

Increments a cache entry value by the specified amount.

isActive()

Gets the current activity state of the cache (on or off).

locale()

Looks up class-specific locale strings based on a key.

save()

Inserts/updates cache entry data.

setActive()

Makes the cache active (true) or inactive (false).



Local