1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore\Ext;
interface ICache {
/**
* Connection `name` key for constructor configuration array.
* @var string
*/
const CONNECTION_NAME = 'name';
/**
* Connection `host` key for constructor configuration array.
* @var string
*/
const CONNECTION_HOST = 'host';
/**
* Connection `port` key for constructor configuration array.
* @var string
*/
const CONNECTION_PORT = 'port';
/**
* Connection `database` name key for constructor configuration array.
* @var string
*/
const CONNECTION_DATABASE = 'database';
/**
* Connection `timeout` key for constructor configuration array.
* @var string
*/
const CONNECTION_TIMEOUT = 'timeout';
/**
* Cache tag records prefix: `cache.tag.`.
* @var string
*/
const TAG_PREFIX = 'cache.tag.';
/**
* Create or get cached redis cache wrapper instance.
* @param string|array|NULL $connectionArguments...
* If string, it's used as connection name.
* If array, it's used as connection config array with keys:
* - `name` default: 'default'
* - `host` default: '127.0.0.1'
* - `port` default: depends on implementation
* - `database` default: $_SERVER['SERVER_NAME']
* - `timeout` default: NULL
* If NULL, there is returned `default` connection
* name with default initial configuration values.
* @return \MvcCore\Ext\Cache
*/
public static function GetInstance (/*...$connectionNameOrArguments = NULL*/);
/**
* Connect to redis server by configuration given in constructor.
* Return boolean about connection success (not about cache enabled or disabled).
* @return bool
*/
public function Connect ();
/**
* Get resource instance.
* @return resource|object|NULL
*/
public function GetResource ();
/**
* Set resource instance.
* @param resource|object $resource
* @return \MvcCore\Ext\Cache
*/
public function SetResource ($resource);
/**
* Return initial configuration data.
* @return \stdClass
*/
public function GetConfig ();
/**
* Enable/disable cache component.
* @param bool $enable
* @return \MvcCore\Ext\Cache
*/
public function SetEnabled ($enabled);
/**
* Get if cache component is enabled/disabled.
* @return bool
*/
public function GetEnabled ();
/**
* Process given operations in transaction mode.
* @param array $ops Keys are client functions names, values are functions arguments.
* @return array
*/
public function ProcessTransaction (array $ops = []);
/**
* Set content under key with seconds expiration and tag(s).
* @param string $key
* @param mixed $content
* @param int $expirationSeconds
* @param array $cacheTags
* @return bool
*/
public function Save ($key, $content, $expirationSeconds = NULL, $cacheTags = []);
/**
* Set multiple contents under keys with seconds expirations and tags.
* @param array $keysAndContents
* @param int $expirationSeconds
* @param array $cacheTags
* @return bool
*/
public function SaveMultiple ($keysAndContents, $expirationSeconds = NULL, $cacheTags = []);
/**
* Return mixed content from cache by key or return `NULL` if content doens't
* exist in cache for given key.
* @param string $key
* @param callable|NULL $notFoundCallback function ($cache, $cacheKey) { ... $cache->Save($cacheKey, $data); return $data; }
* @return mixed|NULL
*/
public function Load ($key, callable $notFoundCallback = NULL);
/**
* Get content by key.
* @param \string[] $keys
* @param callable|NULL $notFoundCallback function ($cache, $cacheKey) { ... $cache->Save($cacheKey, $data); return $data; }
* @return mixed|NULL
*/
public function LoadMultiple (array $keys, callable $notFoundCallback = NULL);
/**
* Delete cache record by key.
* @param string $key
* @return bool
*/
public function Delete ($key);
/**
* Delete cache record(s) by key(s).
* @param array $keys
* @param array $keysTags
* @return int
*/
public function DeleteMultiple (array $keys, array $keysTags = []);
/**
* Delete cache record by key.
* @param string|array $tags
* @return int
*/
public function DeleteByTags ($tags);
/**
* Return `1` if cache has any record under given key, `0` if not.
* @param string $key
* @return int
*/
public function Has ($key);
/**
* Return `1` if cache has any record under given key, `0` if not.
* @param string $key
* @return int
*/
public function HasMultiple ($keys);
/**
* Remove everything from used cache database.
* @return bool
*/
public function Clear ();
}