Download the PHP package corollarium/cachearium without Composer
On this page you can find all versions of the php package corollarium/cachearium. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download corollarium/cachearium
More information about corollarium/cachearium
Files in corollarium/cachearium
Package cachearium
Short Description Cache in your PHP applications. Fast, simple and with easy invalidation.
License MIT
Homepage https://github.com/Corollarium/cachearium
Informations about the package cachearium
Cachearium
High level cache in your PHP applications. What, another one? Nope, this one is better. Fast, simple and with easy invalidation. Includes:
- recursive cache system, all the nested russian dolls you ever wanted
- easy to integrate with your existing classes
- key based cache expiration, no more headaches to invalidate stuff
- multiple dependencies
- lifetime expiration, because stuff rots
- low level cache storage access, when you want to go raw
- lots of examples and tests ready to copy/paste
- variable fragments for things that are almost the same but not quite
- pluggable backend modules: RAM, Memcached, Filesystem and you can add your own
- live in your webpage
Cachearium was developed by Corollarium because we needed a great cache system.
Installation
Composer
Add this to your composer.json: see packagist
If you prefer the cutting edge version, with only the freshest bugs:
Manual
No composer? No fret!
- Download the package
- Include
require_once('cachearium/Cached.php');
Debug and profile
Live cache probes
Image showing cache debug probes. Pink areas are not cached. Green areas are cached. Note that they are nested. The red squares show the dialog with information about each cache hit/miss so you can easily see the cache key, which backend was used and other relevant information.
Probes are only available when you call start()/end().
To see a detailed log
Use cases/examples
See the example/ directory, because it's all there for you. Really, just point a webserver there and play.
Store a single value and invalidate it
This is basic storage.
Store using CacheData
CacheData provides a more sophisticated class to store values.
Store a value with multiple dependencies
You can have multiple dependencies so you can invalidate all cache data that relate to a certain key.
Example: Store searches and invalidate them when an attribute is written to
Cache associated with an object/model that you can easily clean
It's likely that you have a MVC application. Model classes can easily cache data
Nested cache for contents. Useful for generating HTML made of fragments
This uses the russian doll approach to bubble up any invalidations. This means that if you have a list of items and you change one of them, you only invalidate its own cache entry and the entry for the whole list. You can regenerate the list with a single DB hit.
Cache with a variable fragment
This is how to handle something such as a site header, that is almost completely the same except for a small part that varies for each user.
Always add something specific to the cache keys
Let's say for example you have a multi-language website. Caching fragments will always need to add the language as part of the key. Cachearium provides a simple way to do this by creating a special function:
This will be added automatically to your keys in every call to start(). If you need to override this for a single call, use recursiveStart() instead.
Cleaning the house
You can clear the entire cache with $cache->clear()
or CacheAbstract::clearAll()
.
Backends
Null
Does nothing. You can use it to turn off your caches for tests without changing any code calls.
RAM
Caches in RAM, for the duration of the request only. Useful for quick caches that should not persist between requests.
Memcache
Uses Memcache as a backend, and stores data in RAM temporarily to avoid repeated requests in the same run.
Filesystem
Stores in the filesystem.