Skip to content

Instantly share code, notes, and snippets.

@dragoonis
Last active December 14, 2015 12:28
Show Gist options
  • Save dragoonis/5086219 to your computer and use it in GitHub Desktop.
Save dragoonis/5086219 to your computer and use it in GitHub Desktop.
<?php
namespace Psr\Cache;
use Psr\CacheItem;
interface Cache
{
/**
* Remove an item from the cache by its unique key
*
* @param string $key The unique cache key of the item to remove
* @return boolean The result of the delete operation
*/
public function remove($key);
/**
* This will wipe out the entire cache's keys
*
* @return boolean The result of the empty operation
*/
public function empty();
/**
* Persisting our data in the cache, uniquely referenced by a key with an optional expiration TTL time.
*
* @param string $key The key of the item to store
* @param mixed $val The value of the item to store
* @param null|integer $ttl Optional. The TTL value of this item as a timestamp for when it will expire if
* the implementing library choose to use this value
* @return boolean
*/
public function set($key, $val, $ttl = null);
/**
* Here we pass in a cache key to be fetched from the cache.
* A CacheItem object will be constructed and returned to us
*
* @param string $key The unique key of this item in the cache
* @return CacheItem The newly populated CacheItem class representing the stored data in the cache
*/
public function getItem($key);
/**
* This method can be used for re-persistence of an existing cache item after being retrieved from Cache->
* It's good if you have an existing CacheItem and just want to change its value then you can stick it back in the cache
* If the TTL is not null then the TTL value for the Item will be overwritten either by this new TTL value
*
* @param CacheItem $item The CacheItem object being passed for persistence in the cache
* @param null|integer $ttl Optional. If there is an expiration time for this object then this parameter is used.
* @return boolean The result of the set operation
*/
public function setItem(CacheItem $item, $ttl = null);
/**
* Remove multiple cache items in a single operation
*
* @param array $keys The array of keys to be removed
* @return array An array of 'key' => result, elements. Each array row has the key being deleted
* and the result of that operation. The result will be a boolean of true or false
* representing if the cache item was removed or not
*/
public function removeItems($keys);
/**
* Obtain multiple CacheItems by their unique keys
*
* @param array $keys A list of keys that can obtained in a single operation.
* @return array An array of CacheItem classes.
* The resulting array must use the CacheItem's key as the associative key for the array.
*/
public function getItems($keys);
/**
* Persistence or re-persistence of multiple CacheItem objects,
* this does not differ from the setItem() method except that it's setting multiple items at once
* If the TTL is not null then the TTL value for the Item will be overwritten either by this new TTL value
*
* @param array $items An array of CacheItem objects, this is for a multiple-set operation.
* @param null|integer $ttl Optional. If the implementing library has expiration support then the TTL timestamp value is passed in here.
* @return boolean The result of the multiple-set operation
*/
public function setItems($items, $ttl = null);
}
<?php
namespace Psr\Cache;
interface CacheItem
{
/**
* Get the key associated with this CacheItem
*
* @return string
*/
public function getKey();
/**
* Obtain the value of this cache item
*
* @return mixed
*/
public function getValue();
/**
* This boolean value tells us if our cache item is currently in the cache or not
*
* @return boolean
*/
public function isHit();
/**
* @param mixed $value
*/
public function setValue($value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment