Commit 7b5937fe authored by totten's avatar totten

\Civi::cache() - Add shorthand for accessing cache.

parent 9f49773e
......@@ -29,6 +29,31 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
*
* CRM_Utils_Cache_Interface
*
* PHP-FIG has been developing a draft standard for caching,
* PSR-6. The standard has not been ratified yet. When
* making changes to this interface, please take care to
* avoid *conflicst* with PSR-6's CacheItemPoolInterface. At
* time of writing, they do not conflict. Avoiding conflicts
* will enable more transition paths where Civi
* simultaneously supports both interfaces in the same
* implementation.
*
* For example, the current interface defines:
*
* function get($key) => mixed $value
*
* and PSR-6 defines:
*
* function getItem($key) => ItemInterface $item
*
* These are different styles (e.g. "weak item" vs "strong item"),
* but the two methods do not *conflict*. They can coexist,
* and you can trivially write adapters between the two.
*
* @see https://github.com/php-fig/fig-standards/blob/master/proposed/cache.md
*/
interface CRM_Utils_Cache_Interface {
......
......@@ -25,6 +25,26 @@ class Civi {
*/
public static $statics = array();
/**
* EXPERIMENTAL. Retrieve a named cache instance.
*
* This interface is flagged as experimental due to political
* ambiguity in PHP community -- PHP-FIG has an open but
* somewhat controversial draft standard for caching. Based on
* the current draft, it's expected that this function could
* simultaneously support both CRM_Utils_Cache_Interface and
* PSR-6, but that depends on whether PSR-6 changes any more.
*
* @param string $name
* The name of the cache. The 'default' cache is biased toward
* high-performance caches (eg memcache/redis/apc) when
* available and falls back to single-request (static) caching.
* @return CRM_Utils_Cache_Interface
*/
public static function cache($name = 'default') {
return \Civi\Core\Container::singleton()->get('cache.' . $name);
}
/**
* Get the service container.
*
......
......@@ -110,6 +110,7 @@ class Container {
$singletons = array(
'resources' => 'CRM_Core_Resources',
'httpClient' => 'CRM_Utils_HttpClient',
'cache.default' => 'CRM_Utils_Cache',
// Maybe? 'config' => 'CRM_Core_Config',
// Maybe? 'smarty' => 'CRM_Core_Smarty',
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment