Open Journal Systems  3.3.0
APCCache.inc.php
1 <?php
2 
18 import('lib.pkp.classes.cache.GenericCache');
19 
20 class apc_false {};
21 
22 class APCCache extends GenericCache {
30  parent::__construct($context, $cacheId, $fallback);
31  }
32 
36  function flush() {
37  $prefix = INDEX_FILE_LOCATION . ':' . $this->getContext() . ':' . $this->getCacheId();
38  $info = apc_cache_info('user');
39  foreach ($info['cache_list'] as $entry) {
40  if (substr($entry['info'], 0, strlen($prefix)) == $prefix) apc_delete($entry['info']);
41  }
42  }
43 
49  function getCache($id) {
50  $key = INDEX_FILE_LOCATION . ':'. $this->getContext() . ':' . $this->getCacheId() . ':' . $id;
51  $returner = unserialize(apc_fetch($key));
52  if ($returner === false) return $this->cacheMiss;
53  if (get_class($returner) === 'apc_false') $returner = false;
54  return $returner;
55  }
56 
63  function setCache($id, $value) {
64  $key = INDEX_FILE_LOCATION . ':'. $this->getContext() . ':' . $this->getCacheId() . ':' . $id;
65  if ($value === false) $value = new apc_false;
66  apc_store($key, serialize($value));
67  }
68 
74  function getCacheTime() {
75  return null;
76  }
77 
83  function setEntireCache($contents) {
84  foreach ($contents as $id => $value) {
85  $this->setCache($id, $value);
86  }
87  }
88 }
89 
90 
APCCache
Provides caching based on APC's variable store.
Definition: APCCache.inc.php:22
APCCache\flush
flush()
Definition: APCCache.inc.php:36
APCCache\getCacheTime
getCacheTime()
Definition: APCCache.inc.php:74
GenericCache\getContext
getContext()
Definition: GenericCache.inc.php:121
GenericCache\getCacheId
getCacheId()
Definition: GenericCache.inc.php:128
INDEX_FILE_LOCATION
const INDEX_FILE_LOCATION
Definition: index.php:64
APCCache\__construct
__construct($context, $cacheId, $fallback)
Definition: APCCache.inc.php:29
GenericCache\$cacheMiss
$cacheMiss
Definition: GenericCache.inc.php:35
APCCache\setCache
setCache($id, $value)
Definition: APCCache.inc.php:63
GenericCache\$fallback
$fallback
Definition: GenericCache.inc.php:45
APCCache\getCache
getCache($id)
Definition: APCCache.inc.php:49
GenericCache\$context
$context
Definition: GenericCache.inc.php:28
APCCache\setEntireCache
setEntireCache($contents)
Definition: APCCache.inc.php:83
GenericCache
Provides implementation-independent caching. Although this class is intended to be overridden with a ...
Definition: GenericCache.inc.php:23
apc_false
Definition: APCCache.inc.php:20
GenericCache\$cacheId
$cacheId
Definition: GenericCache.inc.php:33