DEFAULT_LIFETIME
DEFAULT_LIFETIME
Default cache lifetime (1 hour)
An object to manage a simple cache
The cache is backed by a MySQL database, with data stored as key => data
pairs. All data stored is must be serializable.
__construct(\mysqli $sql = null, string $table = null, string $key = null, string $cache = null, boolean $purge = false) : void
Create a a new SimpleCache
| \mysqli | $sql | (Optional) |
| string | $table | (Optional) Cache table name in database |
| string | $key | (Optional) Cache key field name in database |
| string | $cache | (Optional) Cache storage field name in database |
| boolean | $purge | (Optional) Automatically purge expired items upon
construction (Defaults to |
setLifetime(integer $lifetimeInSeconds = self::DEFAULT_LIFETIME) : \Battis\void;
Set default lifetime of cached data
This lifetime will be used for all new and updated caches that do not explicitly override it.
| integer | $lifetimeInSeconds | Defaults to DEFAULT_LIFETIME, values less than zero are treated as zero |
buildCache(string $table = null, string $key = null, string $cache = null) : boolean
Create cache table in database
| string | $table | (Optional) Cache table name |
| string | $key | (Optional) Cache key field name |
| string | $cache | (Optional) Cache storage field name |
Returns TRUE on success, FALSE on failure
purgeExpired(boolean $useLocalLifetime = false) : boolean
Purge expired cache data
By default, this purges only cached data that has its own expiration set
explicitly, however, if the option to $useLocalLifetime is set to TRUE,
the cache lifetime default (set by setLifetime(), defaulting to
DEFAULT_LIFETIME) will be compared the timestamps as well, purging cache
data without explicitly set expirations.
| boolean | $useLocalLifetime | (Optional) Defaults to |
Returns TRUE on success, FALSE on failure
sqlInitialized() : boolean
Test for database connection initialization
If the database connection is not initalized, attempt to do so.
DATABASE_NOT_INITIALIZED If the backing database connection cannot be initialized
Returns TRUE if database connection is ready