Facade for caching in the database.

Requires Prefs::DB_CACHE to be set to a database connection. The class will automatically switch to this database and then back everytime it uses the database. Database caching can be useful if you want to share information across multiple instances (like multiple servers) which are part of the same system. It can also allow more persistance. However, it is usually better (faster!) to use an in-memory cache such as APC if there is a single instance or MemCache for multiple instances.

package dstruct_common
todo Easy way to set up the database?

 Methods

Add entry to cache.

add(string $key, string $var, integer $expire) : boolean

Will add an entry if $key does not already exist.

see \DStructCacheInterface::add()

Parameters

$key

string

Key in the cache

$var

string

to cache

$expire

integer

Time in seconds. Default = 604800 = one week

Returns

booleanTrue for success

Clear the cache.

clear() 

SEE WARNING BELOW.

WARNING: This will currently clear the entire cache, not just the entries for this application! Use with extreme caution.

todo restrict to cache entries which are part of this application!

Delete from cache.

delete(string $key) : boolean
see \DStructCacheInterface::delete()

Parameters

$key

string

Key in the cache

Returns

boolean

Get data from cache.

get(string $key) : string
see \DStructCacheInterface::get()

Parameters

$key

string

Key in the cache

Returns

string

Get instance of the Singleton object.

getInstance() : \DatabaseCache
Static

Objects are singletons and so use this method to get an instance. If you impliment this interface, it is recommended that you declare the __constructor() as protected

Returns

Server is available?

hasServer() : boolean

Is the cache server this object uses available to be used by the system

see \DStructCacheInterface::hasServer()

Returns

boolean

Cache hits.

hits() : integer

Not persistent. Counts the number of times this cache object has been queried and returned existing data. Please check the documentation for each classes implimentation of this method, as the functionallity may vary across classes.

see \DStructCacheInterface::hits()

Returns

integer

Cache misses.

misses() : integer

Not persistent. Counts the number of times this cache object has been queried but had no data for that key. Please check the documentation for each classes implimentation of this method, as the functionallity may vary across classes.

see \DStructCacheInterface::misses()

Returns

integer

Scavenge any expired cache entries.

scavenge() : integer

Returns

integerThe number of records deleted

Sets a new entry or overwrites an existing one.

set(string $key, string $var, integer $expire) : boolean
see \DStructCacheInterface::set()

Parameters

$key

string

Key in the cache

$var

string

$expire

integer

Time in seconds. Default = 604800 = one week

Returns

booleanTRUE if value was actually added, FALSE if otherwise

Cache writes.

writes() : integer

Not persistent. Counts the number of times this cache object has been written to. Please check the documentation for each classes implimentation of this method, as the functionallity may vary across classes.

see \DStructCacheInterface::writes()

Returns

integer

Class constructor.

__construct() 

Class is a Singleton so use getInstance().

Prepares and executes an SQL statement.

doStatement(string $statement, array $values) : object
InheritedStatic

Caches prepared statements via prepareStatement().

inherited_from \Base::doStatement()

Parameters

$statement

string

SQL statement

$values

array

Values for SQL statement

Returns

objectExecuted PDO::Statement

Prepare an SQL statement and return the handle.

prepareStatement(string $statement) : object
InheritedStatic

If previously prepared, returns the cached statement handle.
This method is usually called by doStatement().

inherited_from \Base::prepareStatement()

Parameters

$statement

string

SQL statement to prepare

Returns

objectPDO::Statement

 Properties

 

$statements : array
Inherited
inherited_from \Base::$$statements
 

$failedwrites : integer
 

$hasserver : boolean
 

$hits : integer
 

$instance : object
 

$misses : integer
 

$sql_add : string
 

$sql_clear : string
 

$sql_delete : string
 

$sql_get : string
 

$sql_scavenge : string
 

$sql_set : string
 

$writes : integer