This is the main class of the Cache package. It gives you a handy interface to create and manage multiple caches at once. It enables you to configure all caches you need in your application in a central place and access them on demand in any place in your application.
The use of ezcCacheManager is not required, but recommended. If you only need a few (or maybe just 1) cache instance, you can use and instantiate a ezcCacheStorage class directly.
Usage example for ezcCacheManager:
Source for this file: /Cache/src/manager.php
Version: | //autogentag// |
public static void |
createCache(
$id
, [ $location
= null] , $storageClass
, [ $options
= array()] )
Creates a new cache in the manager. |
public static ezcCacheStorage |
getCache(
$id
)
Returns the ezcCacheStorage object with the given ID. |
Creates a new cache in the manager.
This method is used to create a new cache inside the manager. Each cache has a unique ID to access it during the application runtime. Each location may only be used by 1 cache.
The $storageClass parameter must be a subclass of ezcCacheStorage and tells the manager which object will be used for the cache.
The $location parameter depends on the kind of ezcCacheStorage used for the cache you create. Usually this is a directory on your file system, but may also be e.g. a data source name, if you cache in a database or similar. For memory-based storage (ezcCacheStorageApcPlain or ezcCacheStorageMemcachePlain) it is null, but for memory/file hybrid storage (ezcCacheStorageFileApcArray) it should be an existing writeable path.
The $options array consists of several standard attributes and can additionally contain options defined by the ezcCacheStorage class. Standard options are:
Name | Type | Description |
---|---|---|
$id |
string | ID of the cache to create. |
$location |
string | Location to create the cache in. Null for memory-based storage and an existing writeable path for file or memory/file storage. |
$storageClass |
string | Subclass of ezcCacheStorage. |
$options |
array(string=>string) | Options for the cache. |
Type | Description |
---|---|
ezcBaseFileNotFoundException |
If the given location does not exist or is not a directory (thrown by sanity checks performed when storing the configuration of a cache to ensure the latter calls to ezcCacheManager::getCache() do not fail). |
ezcBaseFilePermissionException |
If the given location is not read/writeable (thrown by sanity checks performed when storing the configuration of a cache to ensure the latter calls to ezcCacheManager::getCache() do not fail). |
ezcCacheInvalidStorageClassException |
If the given storage class does not exist or is no subclass of ezcCacheStorage. |
ezcCacheUsedLocationException |
If the given location is already in use by another cache. |
Returns the ezcCacheStorage object with the given ID.
The cache ID has to be defined before using the ezcCacheManager::createCache() method. If no instance of this cache does exist yet, it's created on the fly. If one exists, it will be reused.
Name | Type | Description |
---|---|---|
$id |
string | The ID of the cache to return. |
Type | Description |
---|---|
ezcCacheInvalidIdException |
If the ID of a cache you try to access does not exist. To access a cache using this method, it first hast to be created using ezcCacheManager::createCache(). |
ezcBasePropertyNotFoundException |
If you tried to set a non-existent option value. The accepted options depend on the ezcCacheStorage implementation and may vary. |
ezcBaseFileNotFoundException |
If the storage location does not exist. This should usually not happen, since ezcCacheManager::createCache() already performs sanity checks for the cache location. In case this exception is thrown, your cache location has been corrupted after the cache was configured. |
ezcBaseFileNotFoundException |
If the storage location is not a directory. This should usually not happen, since ezcCacheManager::createCache() already performs sanity checks for the cache location. In case this exception is thrown, your cache location has been corrupted after the cache was configured. |
ezcBaseFilePermissionException |
If the storage location is not writeable. This should usually not happen, since ezcCacheManager::createCache() already performs sanity checks for the cache location. In case this exception is thrown, your cache location has been corrupted after the cache was configured. |