Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Last active December 25, 2015 13:08
Show Gist options
  • Save guilhermeblanco/6981006 to your computer and use it in GitHub Desktop.
Save guilhermeblanco/6981006 to your computer and use it in GitHub Desktop.
PSR 7: Managed Cache
<?php
namespace Psr\Cache;
interface CacheInterface extends PSR6SimplifiedCacheInterface
{
/**
* Retrieve the Cache Manager.
*
* @return ManagerInterface
*/
public function getManager();
/**
* Retrieve the Cache Configuration.
*
* @return ConfigurationInterface
*/
public function getConfiguration();
/**
* Return the name of the cache.
*
* @return string
*/
public function getName();
/* ADDING EXCEPTIONS TO SITUATIONS ON PSR6SimplifiedCacheInterface */
/**
* Retrieve a Cache Entry.
*
* @param string $key
*
* @throws Exception\IllegalStateException If the Cache Manager is closed.
* @throws Exception\CommunicationException If there was a problem fetching for key.
* @throws \InvalidArgumentException If argument could not be properly validated.
* Fetching should only validate if key is a string.
*
* @return EntryInterface
*/
public function get($key);
/**
* Define a Cache Entry.
*
* @param EntryInterface $entry
*
* @throws Exception\IllegalStateException If the Cache Manager is closed.
* @throws Exception\CommunicationException If there was a problem fetching for key.
* @throws \InvalidArgumentException If argument could not be properly validated.
* (useful when subclassing EntryInterface).
*
* @return boolean
*/
public function set(EntryInterface $entry);
/**
* Remove a Cache Entry.
*
* @param string $key
*
* @throws Exception\IllegalStateException If the Cache Manager is closed.
* @throws Exception\CommunicationException If there was a problem fetching for key.
* @throws \InvalidArgumentException If argument could not be properly validated.
* Fetching should only validate if key is a string.
*
* @return boolean
*/
public function unset($key);
/**
* Check existance of a Cache Entry.
*
* @param string $key
*
* @throws Exception\IllegalStateException If the Cache Manager is closed.
* @throws Exception\CommunicationException If there was a problem fetching for key.
* @throws \InvalidArgumentException If argument could not be properly validated.
* Fetching should only validate if key is a string.
*
* @return boolean
*/
public function isset($key);
}
<?php
namespace Psr\Cache;
interface ConfigurationInterface
{
/* ADDED TTL EXAMPLE SUPPORT HERE */
/**
* Retrieve the Cache expiration (TTL) in seconds.
*
* @return integer
*/
public function getExpiration();
/**
* Define the Cache expiration (TTL) in seconds.
*
* @param integer $expiration
*/
public function setExpiration($expiration);
}
<?php
namespace Psr\Cache;
interface ManagerInterface
{
/**
* Configure a new Cache to be managed by the Cache Manager.
*
* @param string $name
* @param ConfigurationInterface $configuration
*
* @return CacheInterface
*/
public function configureCache($name, ConfigurationInterface $configuration);
/**
* Destroy a managed Cache instance.
*
* @param string $name
*
* @return void
*/
public function destroyCache($name);
/**
* Retrieve a managed Cache instance.
*
* @param string $name
*
* @return CacheInterface
*/
public function getCache($name);
/**
* Retrieve an Iterator of managed Cache instance names.
*
* @return array<string>
*/
public function getCacheNameList();
/**
* Close the Cache Manager.
*
* @return void
*/
public function close();
/**
* Check if the Cache Manager is closed.
*
* @return boolean
*/
public function isClosed();
/**
* Check if a requested feature is supported by Cache Manager.
*
* @param string $feature
*
* @return boolean
*/
public function isSupported($feature);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment