~ubuntu-branches/ubuntu/wily/php-horde-cache/wily

« back to all changes in this revision

Viewing changes to Horde_Cache-2.2.1/lib/Horde/Cache/Storage/Base.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-10-08 18:54:29 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20131008185429-8r3ao97k5z15l325
Tags: 2.3.0-1
New upstream version 2.3.0

Show diffs side-by-side

added added

removed removed

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