CachePDO

Database-based caching class using PHP Data Objects (PDO).

Version

2008.11.30

Copyright

2006-2008 LifeNexus Digital, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

Tarzanhttp://tarzan-aws.com
PDOhttp://php.net/pdo

CachePDO

Container for all PDO-based cache methods.  Inherits additional methods from CacheCore.

Properties

pdo

Reference to the PDO connection object.

dsn

Holds the parsed URL components.

dsn_string

Holds the PDO-friendly version of the connection string.

create

Holds the prepared statement for creating an entry.

read

Holds the prepared statement for reading an entry.

update

Holds the prepared statement for updating an entry.

reset

Holds the prepared statement for resetting the expiry of an entry.

delete

Holds the prepared statement for deleting an entry.

store_read

Holds the response of the read so we only need to fetch it once instead of doing multiple queries.

Functions

__construct()

public function __construct($name,
$location,
$expires)

The constructor.

Tested with MySQL 5.0.x (http://mysql.com), PostgreSQL (http://postgresql.com), and SQLite 3.x (http://sqlite.org).  SQLite 2.x is assumed to work.  No other PDO-supported databases have been tested (e.g.  Oracle, Microsoft SQL Server, IBM DB2, ODBC, Sybase, Firebird).  Feel free to send patches for additional database support.  See http://php.net/pdo for more information.

Access

public

Parameters

namestring (Required) A name to uniquely identify the cache object.
locationstring (Required) The location to store the cache object in.  This may vary by cache method.
expiresinteger (Required) The number of seconds until a cache object is considered stale.

Returns

object Reference to the cache object.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

create()

public function create($data)

Creates a new cache.

Access

public

Parameters

datamixed (Required) The data to cache.

Returns

boolean Whether the operation was successful.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

read()

public function read()

Reads a cache.

Access

public

Returns

mixed Either the content of the cache object, or boolean false.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

update()

public function update($data)

Updates an existing cache.

Access

public

Parameters

datamixed (Required) The data to cache.

Returns

boolean Whether the operation was successful.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

delete()

public function delete()

Deletes a cache.

Access

public

Returns

boolean Whether the operation was successful.

timestamp()

public function timestamp()

Retrieves the timestamp of the cache.

Access

public

Returns

mixed Either the Unix timestamp of the cache creation, or boolean false.

reset()

public function reset()

Resets the freshness of the cache.

Access

public

Returns

boolean Whether the operation was successful.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

is_expired()

public function is_expired()

Checks whether the cache object is expired or not.

Access

public

Returns

boolean Whether the cache is expired or not.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/cachecore/cache.phps

get_drivers()

public function get_drivers()

Returns a list of supported PDO database drivers.  Identical to PDO::getAvailableDrivers().

Access

public

Returns

array The list of supported database drivers.

See Also

PHP Methodhttp://php.net/pdo.getavailabledrivers

generate_timestamp()

private function generate_timestamp()

Returns a timestamp value apropriate to the current database type.

Access

private

Returns

mixed Timestamp for MySQL and PostgreSQL, integer value for SQLite.