/library/Zend/Cache/Storage/Adapter.php

https://github.com/bradley-holt/zf2 · PHP · 426 lines · 45 code · 47 blank · 334 comment · 0 complexity · 0aeef684684e10fed316ec35975515f2 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cache
  17. * @subpackage Storage
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. namespace Zend\Cache\Storage;
  22. /**
  23. * @category Zend
  24. * @package Zend_Cache
  25. * @subpackage Storage
  26. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. interface Adapter
  30. {
  31. /**
  32. * Match expired items
  33. *
  34. * @var int
  35. */
  36. const MATCH_EXPIRED = 01;
  37. /**
  38. * Match active items
  39. *
  40. * @var int
  41. */
  42. const MATCH_ACTIVE = 02;
  43. /**
  44. * Match active and expired items
  45. *
  46. * @var int
  47. */
  48. const MATCH_ALL = 03;
  49. /**
  50. * Match tag(s) using OR operator
  51. *
  52. * @var int
  53. */
  54. const MATCH_TAGS_OR = 000;
  55. /**
  56. * Match tag(s) using AND operator
  57. *
  58. * @var int
  59. */
  60. const MATCH_TAGS_AND = 010;
  61. /**
  62. * Negate tag match
  63. *
  64. * @var int
  65. */
  66. const MATCH_TAGS_NEGATE = 020;
  67. /**
  68. * Match tag(s) using OR operator and negates result
  69. *
  70. * @var int
  71. */
  72. const MATCH_TAGS_OR_NOT = 020;
  73. /**
  74. * Match tag(s) using AND operator and negates result
  75. *
  76. * @var int
  77. */
  78. const MATCH_TAGS_AND_NOT = 030;
  79. /* configuration */
  80. /**
  81. * Set options.
  82. *
  83. * @param array|Traversable|Adapter\AdapterOptions $options
  84. * @return Adapter
  85. */
  86. public function setOptions($options);
  87. /**
  88. * Get options
  89. *
  90. * @return Adapter\AdapterOptions
  91. */
  92. public function getOptions();
  93. /* reading */
  94. /**
  95. * Get an item.
  96. *
  97. * @param string $key
  98. * @param array $options
  99. * @return mixed Data on success and false on failure
  100. * @throws \Zend\Cache\Exception
  101. */
  102. public function getItem($key, array $options = array());
  103. /**
  104. * Get multiple items.
  105. *
  106. * @param array $keys
  107. * @param array $options
  108. * @return array Associative array of existing keys and values
  109. * @throws \Zend\Cache\Exception
  110. */
  111. public function getItems(array $keys, array $options = array());
  112. /**
  113. * Test if an item exists.
  114. *
  115. * @param string $key
  116. * @param array $options
  117. * @return boolean
  118. * @throws \Zend\Cache\Exception
  119. */
  120. public function hasItem($key, array $options = array());
  121. /**
  122. * Test multiple items.
  123. *
  124. * @param array $keys
  125. * @param array $options
  126. * @return array Array of existing keys
  127. * @throws \Zend\Cache\Exception
  128. */
  129. public function hasItems(array $keys, array $options = array());
  130. /**
  131. * Get metadata of an item.
  132. *
  133. * @param string $key
  134. * @param array $options
  135. * @return array|boolean Metadata or false on failure
  136. * @throws \Zend\Cache\Exception
  137. */
  138. public function getMetadata($key, array $options = array());
  139. /**
  140. * Get multiple metadata
  141. *
  142. * @param array $keys
  143. * @param array $options
  144. * @return array Associative array of existing cache ids and its metadata
  145. * @throws \Zend\Cache\Exception
  146. */
  147. public function getMetadatas(array $keys, array $options = array());
  148. /* writing */
  149. /**
  150. * Store an item.
  151. *
  152. * @param string $key
  153. * @param mixed $value
  154. * @param array $options
  155. * @return boolean
  156. * @throws \Zend\Cache\Exception
  157. */
  158. public function setItem($key, $value, array $options = array());
  159. /**
  160. * Store multiple items.
  161. *
  162. * @param array $keyValuePairs
  163. * @param array $options
  164. * @return boolean
  165. * @throws \Zend\Cache\Exception
  166. */
  167. public function setItems(array $keyValuePairs, array $options = array());
  168. /**
  169. * Add an item.
  170. *
  171. * @param string $key
  172. * @param mixed $value
  173. * @param array $options
  174. * @return boolean
  175. * @throws \Zend\Cache\Exception
  176. */
  177. public function addItem($key, $value, array $options = array());
  178. /**
  179. * Add multiple items.
  180. *
  181. * @param array $keyValuePairs
  182. * @param array $options
  183. * @return boolean
  184. * @throws \Zend\Cache\Exception
  185. */
  186. public function addItems(array $keyValuePairs, array $options = array());
  187. /**
  188. * Replace an existing item.
  189. *
  190. * @param string $key
  191. * @param mixed $value
  192. * @param array $options
  193. * @return boolean
  194. * @throws \Zend\Cache\Exception
  195. */
  196. public function replaceItem($key, $value, array $options = array());
  197. /**
  198. * Replace multiple existing items.
  199. *
  200. * @param array $keyValuePairs
  201. * @param array $options
  202. * @return boolean
  203. * @throws \Zend\Cache\Exception
  204. */
  205. public function replaceItems(array $keyValuePairs, array $options = array());
  206. /**
  207. * Set an item only if token matches
  208. *
  209. * It uses the token received from getItem() to check if the item has
  210. * changed before overwriting it.
  211. *
  212. * @param mixed $token
  213. * @param string $key
  214. * @param mixed $value
  215. * @param array $options
  216. * @return boolean
  217. * @throws \Zend\Cache\Exception
  218. * @see getItem()
  219. * @see setItem()
  220. */
  221. public function checkAndSetItem($token, $key, $value, array $options = array());
  222. /**
  223. * Reset lifetime of an item
  224. *
  225. * @param string $key
  226. * @param array $options
  227. * @return boolean
  228. * @throws \Zend\Cache\Exception
  229. */
  230. public function touchItem($key, array $options = array());
  231. /**
  232. * Reset lifetime of multiple items.
  233. *
  234. * @param array $keys
  235. * @param array $options
  236. * @return boolean
  237. * @throws \Zend\Cache\Exception
  238. */
  239. public function touchItems(array $keys, array $options = array());
  240. /**
  241. * Remove an item.
  242. *
  243. * @param string $key
  244. * @param array $options
  245. * @return boolean
  246. * @throws \Zend\Cache\Exception
  247. */
  248. public function removeItem($key, array $options = array());
  249. /**
  250. * Remove multiple items.
  251. *
  252. * @param array $keys
  253. * @param array $options
  254. * @return boolean
  255. * @throws \Zend\Cache\Exception
  256. */
  257. public function removeItems(array $keys, array $options = array());
  258. /**
  259. * Increment an item.
  260. *
  261. * @param string $key
  262. * @param int $value
  263. * @param array $options
  264. * @return int|boolean The new value or false on failure
  265. * @throws \Zend\Cache\Exception
  266. */
  267. public function incrementItem($key, $value, array $options = array());
  268. /**
  269. * Increment multiple items.
  270. *
  271. * @param array $keyValuePairs
  272. * @param array $options
  273. * @return boolean
  274. * @throws \Zend\Cache\Exception
  275. */
  276. public function incrementItems(array $keyValuePairs, array $options = array());
  277. /**
  278. * Decrement an item.
  279. *
  280. * @param string $key
  281. * @param int $value
  282. * @param array $options
  283. * @return int|boolean The new value or false on failure
  284. * @throws \Zend\Cache\Exception
  285. */
  286. public function decrementItem($key, $value, array $options = array());
  287. /**
  288. * Decrement multiple items.
  289. *
  290. * @param array $keyValuePairs
  291. * @param array $options
  292. * @return boolean
  293. * @throws \Zend\Cache\Exception
  294. */
  295. public function decrementItems(array $keyValuePairs, array $options = array());
  296. /* non-blocking */
  297. /**
  298. * Request multiple items.
  299. *
  300. * @param array $keys
  301. * @param array $options
  302. * @return boolean
  303. * @throws \Zend\Cache\Exception
  304. * @see fetch()
  305. * @see fetchAll()
  306. */
  307. public function getDelayed(array $keys, array $options = array());
  308. /**
  309. * Find items.
  310. *
  311. * @param int $mode Matching mode (Value of Adapter::MATCH_*)
  312. * @param array $options
  313. * @return boolean
  314. * @throws \Zend\Cache\Exception
  315. * @see fetch()
  316. * @see fetchAll()
  317. */
  318. public function find($mode = self::MATCH_ACTIVE, array $options = array());
  319. /**
  320. * Fetches the next item from result set
  321. *
  322. * @return array|boolean The next item or false
  323. * @throws \Zend\Cache\Exception
  324. * @see fetchAll()
  325. */
  326. public function fetch();
  327. /**
  328. * Returns all items of result set.
  329. *
  330. * @return array The result set as array containing all items
  331. * @throws \Zend\Cache\Exception
  332. * @see fetch()
  333. */
  334. public function fetchAll();
  335. /* cleaning */
  336. /**
  337. * Clear items off all namespaces.
  338. *
  339. * @param int $mode Matching mode (Value of Adapter::MATCH_*)
  340. * @param array $options
  341. * @return boolean
  342. * @throws \Zend\Cache\Exception
  343. * @see clearByNamespace()
  344. */
  345. public function clear($mode = self::MATCH_EXPIRED, array $options = array());
  346. /**
  347. * Clear items by namespace.
  348. *
  349. * @param int $mode Matching mode (Value of Adapter::MATCH_*)
  350. * @param array $options
  351. * @return boolean
  352. * @throws \Zend\Cache\Exception
  353. * @see clear()
  354. */
  355. public function clearByNamespace($mode = self::MATCH_EXPIRED, array $options = array());
  356. /**
  357. * Optimize adapter storage.
  358. *
  359. * @param array $options
  360. * @return boolean
  361. * @throws \Zend\Cache\Exception
  362. */
  363. public function optimize(array $options = array());
  364. /* status */
  365. /**
  366. * Capabilities of this storage
  367. *
  368. * @return Capabilities
  369. */
  370. public function getCapabilities();
  371. /**
  372. * Get storage capacity.
  373. *
  374. * @param array $options
  375. * @return array|boolean Capacity as array or false on failure
  376. * @throws \Zend\Cache\Exception
  377. */
  378. public function getCapacity(array $options = array());
  379. }