1: <?php
2: /**
3: * This class provides the abstract implementation of the cache storage
4: * driver.
5: *
6: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Michael Slusarz <slusarz@horde.org>
12: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @package Cache
15: */
16: abstract class Horde_Cache_Storage_Base
17: {
18: /**
19: * Logger.
20: *
21: * @var Horde_Log_Logger
22: */
23: protected $_logger;
24:
25: /**
26: * Parameters.
27: *
28: * @var array
29: */
30: protected $_params = array();
31:
32: /**
33: * Constructor.
34: *
35: * @param array $params Configuration parameters.
36: */
37: public function __construct(array $params = array())
38: {
39: $this->_params = array_merge($this->_params, $params);
40: }
41:
42: /**
43: * Set the logging object.
44: *
45: * @param Horde_Log_Logger $logger Log object.
46: */
47: public function setLogger($logger)
48: {
49: $this->_logger = $logger;
50: }
51:
52: /**
53: * Retrieve cached data.
54: *
55: * @param string $key Object ID to query.
56: * @param integer $lifetime Lifetime of the object in seconds.
57: *
58: * @return mixed Cached data, or false if none was found.
59: */
60: abstract public function get($key, $lifetime = 0);
61:
62: /**
63: * Store an object in the cache.
64: *
65: * @param string $key Object ID used as the caching key.
66: * @param mixed $data Data to store in the cache.
67: * @param integer $lifetime Object lifetime - i.e. the time before the
68: * data becomes available for garbage
69: * collection. If 0 will not be GC'd.
70: */
71: abstract public function set($key, $data, $lifetime = 0);
72:
73: /**
74: * Checks if a given key exists in the cache, valid for the given
75: * lifetime.
76: *
77: * @param string $key Cache key to check.
78: * @param integer $lifetime Lifetime of the key in seconds.
79: *
80: * @return boolean Existence.
81: */
82: abstract public function exists($key, $lifetime = 0);
83:
84: /**
85: * Expire any existing data for the given key.
86: *
87: * @param string $key Cache key to expire.
88: *
89: * @return boolean Success or failure.
90: */
91: abstract public function expire($key);
92:
93: /**
94: * Clears all data from the cache.
95: *
96: * @throws Horde_Cache_Exception
97: */
98: abstract public function clear();
99:
100: }
101: