Stack.PHP
A simple and easy to use PHP library for the Stack Exchange API.
Public Member Functions | Public Attributes | List of all members
SQLCache Class Reference

Provides a means to use an SQL database for caching purposes. More...

Inheritance diagram for SQLCache:
CacheBase

Public Member Functions

 __construct ($type, $host='', $username=null, $password=null, $database=null)
 Constructor for an SQL cache. More...
 
 RetrieveFromCache ($url)
 Retrieves the data for the given URL from the database. More...
 
 AddToCache ($url, $data, $ttl=null)
 Adds the URL and data to the database. More...
 
 Clear ()
 Clears all rows from the database.
 
 Cleanup ()
 Removes expired rows from the database.
 

Public Attributes

const MySQL = 'mysql:host='
 Represents a MySQL driver.
 
const PostgreSQL = 'pgsql:host='
 Represents a PostgreSQL driver.
 
const SQLite = 'sqlite:'
 Represents a SQLite driver.
 
const SQLiteMemory = 'sqlite::memory:'
 Represents an in-memory SQLite database.
 

Detailed Description

Provides a means to use an SQL database for caching purposes.

Constructor & Destructor Documentation

◆ __construct()

SQLCache::__construct (   $type,
  $host = '',
  $username = null,
  $password = null,
  $database = null 
)

Constructor for an SQL cache.

Parameters
$typethe type of database to connect to
$hostthe host running the SQL server or a local filename (where supported)
$usernamethe username for the SQL database
$passwordthe password for the SQL database
$databasethe database to use for caching

Note: this function also makes sure that the table 'api_cache' exists, attempting to create it if it does not.

Member Function Documentation

◆ AddToCache()

SQLCache::AddToCache (   $url,
  $data,
  $ttl = null 
)

Adds the URL and data to the database.

Parameters
$urlthe URL for the request
$datathe data for the URL
$ttlthe time-to-live (TTL) for the data

Implements CacheBase.

◆ RetrieveFromCache()

SQLCache::RetrieveFromCache (   $url)

Retrieves the data for the given URL from the database.

Parameters
$urlthe URL to retrieve the data for
Returns
the data for the URL or FALSE

Implements CacheBase.


The documentation for this class was generated from the following file: