Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
GenericCache.inc.php
1 <?php
2 
19 // Pseudotype to represent a cache miss
20 class generic_cache_miss {
21 }
22 
23 class GenericCache {
28  var $context;
29 
33  var $cacheId;
34 
35  var $cacheMiss;
36 
45  var $fallback;
46 
51  $this->context = $context;
52  $this->cacheId = $cacheId;
53  $this->fallback = $fallback;
54  $this->cacheMiss = new generic_cache_miss;
55  }
56 
60  function get($id) {
61  $result = $this->getCache($id);
62  if (is_object($result) && get_class($result) === 'generic_cache_miss') {
63  $result = call_user_func_array($this->fallback, array($this, $id));
64  }
65  return $result;
66  }
67 
72  function set($id, $value) {
73  return $this->setCache($id, $value);
74  }
75 
79  function flush() {
80  }
81 
87  function setEntireCache(&$contents) {
88  $this->flush();
89  foreach ($contents as $id => $value) {
90  $this->setCache($id, $value);
91  }
92  }
93 
99  function getCache($id) {
100  return $this->cacheMiss;
101  }
102 
109  function setCache($id, $value) {
110  }
111 
115  function close() {
116  }
117 
121  function getContext() {
122  return $this->context;
123  }
124 
128  function getCacheId() {
129  return $this->cacheId;
130  }
131 
135  function getCacheTime() {
136  // Since it's not really cached, we'll consider it to have been cached just now.
137  return time();
138  }
139 }
140 
141 ?>
set($id, $value)
setCache($id, $value)
GenericCache($context, $cacheId, $fallback)
setEntireCache(&$contents)
Provides implementation-independent caching. Although this class is intended to be overridden with a ...