Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * Base class for all caches
4
 *
5
 * $Id: Cache.php,v 1.1 2005/01/04 22:38:23 schst Exp $
6
 *
7
 * @package Services_Ebay
8
 * @author  Stephan Schmidt <schst@php.net>
9
 */
10
abstract class Services_Ebay_Cache
11
{
12
   /**
13
    * options of the cache
14
    *
15
    * @var  array
16
    */
17
    protected $options = array();
18
 
19
   /**
20
    * stores the expiry object
21
    *
22
    * @var  object
23
    */
24
    protected $expiry = null;
25
 
26
   /**
27
    * constructor
28
    *
29
    * @param    array   options for the cache
30
    */
31
    public function __construct($options)
32
    {
33
    	$this->options = $options;
34
    }
35
 
36
   /**
37
    * load a model from cache
38
    *
39
    * @param    string      model type
40
    * @param    string      primary key
41
    * @param    integer     detail level
42
    * @return   array|boolean
43
    */
44
    abstract public function load($Type, $Key, $DetailLevel);
45
 
46
   /**
47
    * store model data in the cache
48
    *
49
    * @param    string      model type
50
    * @param    string      primary key
51
    * @param    integer     detail level
52
    * @param    array       properties
53
    * @return   boolean
54
    */
55
    abstract public function store($Type, $Key, $DetailLevel, $Props);
56
 
57
   /**
58
    * set the expiry type
59
    *
60
    * Services_Ebay allows custom expiry objects to check the validity of
61
    * a cached model.
62
    * This enables you to create a cache lifetime depending of the
63
    * end of the auction or the version number of a category listing.
64
    *
65
    * The following expiry types have been implemented:
66
    * - Static
67
    *
68
    * @param    string      expiry type
69
    * @param    mixed       parameters for the expiry
70
    */
71
    public function setExpiry($type, $params)
72
    {
73
        $className = 'Services_Ebay_Cache_ExpiryCheck_' . $type;
74
        $fileName  = SERVICES_EBAY_BASEDIR . '/Ebay/Cache/ExpiryCheck/' . $type . '.php';
75
        @include_once $fileName;
76
 
77
        if (!class_exists($className)) {
78
        	throw new Services_Ebay_Exception('Unknown expiry check \''.$type.'\'.');
79
        }
80
 
81
        $this->expiry = new $className($params);
82
        return true;
83
    }
84
 
85
   /**
86
    * check the validity of the cache
87
    *
88
    * @param    string      type of the model
89
    * @param    integer     time the cache has been created
90
    * @param    array       model properties
91
    */
92
    protected function isValid($Type, $ts, $props)
93
    {
94
        if (!is_object($this->expiry)) {
95
        	return true;
96
        }
97
        return $this->expiry->isValid($Type, $ts, $props);
98
    }
99
}
100
?>