Skip to content

Instantly share code, notes, and snippets.

@joshuaadickerson
Created May 8, 2013 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaadickerson/5538182 to your computer and use it in GitHub Desktop.
Save joshuaadickerson/5538182 to your computer and use it in GitHub Desktop.
An interface to implement for caching
<?php
/**
* An interface for caches to implement
*/
interface iCache
{
public function connect();
public function setOptions($options);
public function getKey($key, $parameters);
/**
* Get a single item from the cache
*
* @param string $key What you are looking for
* @param array $parameters Replace parts of the key and used as arguments for the callback
* @param callable $callback If the request fails, call this function and return its results
*/
public function get($key, $parameters, $callback);
/**
* Get multiple items from the cache
* The same as get() but allowed to use multiple keys and no callback
*
* @param array $keys An array of keys you are looking for
* @param array $parameters Replace parts of the key
* @param array $flags Flags to be used
*/
public function getMulti($keys, $parameters, $flags);
/**
* Set a single item in the cache
*
* @param string $key The key under which to store the value
* @param mixed $value The value of the item
* @param int $ttl The amount of time the item shall live for
* @param array $parameters Replace parts of the key
*/
public function set($key, $value, $ttl, $parameters);
/**
* Set multiple items
*
* @param array $array
* @param int $ttl
* @param array $parameters
*/
public function setMulti($array, $ttl, $parameters);
/**
* Delete an item from the cache
* @param type $key
* @param type $parameters
*/
public function delete($key, $parameters);
/**
* Delete multiple items from the cache
*
* @param array $keys
* @param array $parameters
*/
public function deleteMulti($keys, $parameters);
/**
* Increase an item by its offset
*
* @throw Exception if the item is not numeric
*
* @param type $key
* @param type $offset
* @param type $initial_value
* @param type $ttl
* @param type $parameters
*/
public function increment($key, $offset, $initial_value, $ttl, $parameters);
/**
* Lessen an item by its offset
*
* @throw Exception if the item is not numeric
*
* @param type $key
* @param type $offset
* @param type $initial_value
* @param type $ttl
* @param type $parameters
*/
public function decrement($key, $offset, $initial_value, $ttl, $parameters);
/**
* Add an element to the end of a list
*
* @throw Exception if the item is not an array
*
* @param string $key
* @param mixed $value
* @param int $ttl
* @param array $parameters
*/
public function append($key, $value, $ttl, $parameters);
/**
* Add an element to the beginning of a list
*
* @throw an Exception if the item is not an array
*
* @param string $key
* @param mixed $value
* @param int $ttl
* @param array $parameters
*/
public function prepend($key, $value, $ttl, $parameters);
/**
* Get the last element of a list in the cache and remove it
*
* @throw an Exception if the item is not an array
*
* @param type $key
* @param type $parameters
*/
public function pop($key, $parameters);
/**
* Get the first element of a list and remove it
*
* @throw an Exception if the item is not an array
*
* @param string $key
* @param array $parameters
*/
public function shift($key, $parameters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment