Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save jeremeamia/41d4b46495510ea516b8 to your computer and use it in GitHub Desktop.

Select an option

Save jeremeamia/41d4b46495510ea516b8 to your computer and use it in GitHub Desktop.
Simple cache interface idea
<?php
namespace Psr\Cache
interface CacheInterface
{
/**
* @param string $key
* Key for the value in the cache.
* @param bool $isHit
* Value is populated with `true` on hit or `false` on miss. This is
* a simple way to distinguish between falsey values and cache misses,
* such that race conditions can be avoided.
*
* @return mixed
* The cached value.
* @throws CacheException
* If there was a problem retrieving the value from the cache.
*/
public function get($key, &$isHit = null);
/**
* @param string $key
* Key for the value in the cache.
*
* @return bool
* Whether the value exists in the cache.
* @throws CacheException
* If there was a problem checking if the value exists in the cache.
*/
public function has($key);
/**
* @param string $key
* Key for the value in the cache.
* @param mixed $value
* Value to cache.
* @param int|\DateTime $ttl
* - If an integer is passed, it is interpreted as the number of seconds
* after which the item MUST be considered expired.
* - If a DateTime object is passed, it is interpreted as the point in
* time after which the item MUST be considered expired.
* - If null is passed, a default value MAY be used. If none is set,
* the value should be stored permanently or for as long as the
* implementation allows.
*
* @throws CacheException
* If there was a problem saving the value in the cache.
*/
public function set($key, $value, $ttl = null);
/**
* @param string $key
* Key for the value in the cache.
*
* @throws CacheException
* If there was a problem deleted the value from the cache.
*/
public function delete($key);
/**
* @throws CacheException
* If there was a problem clearing the cache.
*/
public function clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment