foolz / cache
Rich girls' caching package. We want everything from dummy to permanent.
Installs: 1 726
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 3
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- doctrine/dbal: >=2.3.0
This package is auto-updated.
Last update: 2024-10-21 06:22:23 UTC
README
Heavy duty caching package, meant for serious sites needing serious caching powers.
Requires PHP 5.4.
The gist
You must give a configuration object to an instance of cache.
<?php Cache::instantiate(Config::forgeApc()); Cache::item('test')->set($value); Cache::item('test')->get(); ?>
And this is all if you use APC.
Storages
Currently bundled storages:
- APC
- Memcached
- DB (Doctrine DBAL) (permanent storage, great for configurations)
- Dummy (always returns not found)
- File
- Volatile (uses PHP Arrays and gets wiped on the end of the process)
Formats
We added several formats that might sound useless. We need the formats to be compatible with extraneous software.
Currently bundled formats:
- ArrayJson (stores the json wrapped as array)
- ObjectJson (stores the json wrapped as object)
- SmartJson (uses an object to store the kind of json)
- Plain
- Serialized
Configuration
You can create a new configuration in two ways:
<?php $config = Config::forgeMemcached(); // or $config = new \Foolz\Cache\Config\Memcached; ?>
IDE hints will appear, helping you configuring the storage. You can also look in the folder classes/Foolz/Cache/Config
for the configurations available.
Base configuration methods
-
$config->getStorage()
Returns the name of the storage
-
$config->setFormat($format)
Set one of the formats:
array_json
,object_json
,smart_json
,plain
,serialized
. -
__$config->getFormat()
Returns the name of the format
-
$config->setPrefix($prefix)
Set a prefix for the stored items
-
$config->getPrefix()
Get the prefix for the stored items
-
$config->setThrow($bool = false)
Pass true if you want failed cache GETs to throw an exception. False if you prefer a fallback value. False by default.
-
$config->getThrow()
True if GETs will throw an exception, false otherwise.
Instantiation
The Cache package features an instance system.
-
Cache::instantiate(\Foolz\Cache\Config $config, $instance_name = 'default')
Create a new link for the caching backend.
-
Cache::destroy($instance_name)
Destroys the link for the cache backend.
-
$item = Cache::forge($instance_name = 'default')
Returns an instance of the link.
-
$item = Cache::item($key, $instance_name = 'default)
Creates an instance paired with a key.
-
$item->getConfig()
Returns the configuration object.
-
$item->getEngine()
Returns the raw storage engine class.
-
$item->getKey()
Returns the key for the item.
-
$item->set($value, $expiration = 0)
Sets a value. Expiration is seconds from now.
-
$item->get()
Returns the stored value. Returns \Foolz\Cache\Void if the value is not found. Throws \OutOfBoundsException if the Throws setting is enabled and the value is not found.
-
$item->delete()
Delete a stored value.
-
$item->flush()
Deletes all the entries in the engine.