4 * @file classes/cache/CacheManager.inc.php
6 * Copyright (c) 2000-2009 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
12 * @brief Provides cache management functions.
16 // $Id: CacheManager.inc.php,v 1.7 2009/09/22 18:36:21 asmecher Exp $
21 * Get the static instance of the cache manager.
22 * @return object CacheManager
24 function &getManager() {
25 $manager =& Registry
::get('cacheManager', true, null);
26 if ($manager === null) {
27 $manager = new CacheManager();
34 * @param $context string
35 * @param $cacheId string
36 * @param $fallback callback
37 * @return object FileCache
39 function &getFileCache($context, $cacheId, $fallback) {
40 import('cache.FileCache');
41 $returner = new FileCache(
42 $context, $cacheId, $fallback,
43 $this->getFileCachePath()
50 * @param $context string
51 * @param $cacheId string
52 * @param $fallback callback
53 * @return object Cache
55 function &getCache($context, $cacheId, $fallback) {
56 $cacheType = Config
::getVar('cache','cache');
59 import('cache.MemcacheCache');
60 $cache = new MemcacheCache(
61 $context, $cacheId, $fallback,
62 Config
::getVar('cache','memcache_hostname'),
63 Config
::getVar('cache','memcache_port')
66 case '': // Provide a default if not specified
68 $cache =& $this->getFileCache($context, $cacheId, $fallback);
71 import('cache.GenericCache');
72 $cache = new GenericCache(
73 $context, $cacheId, $fallback
77 die ("Unknown cache type \"$cacheType\"!\n");
84 * Get the path in which file caches will be stored.
85 * @return string The full path to the file cache directory
87 function getFileCachePath() {
88 return Core
::getBaseDir() . DIRECTORY_SEPARATOR
. 'cache';
92 * Flush an entire context, if specified, or
94 * @param $context string The context to flush, if only one is to be flushed
96 function flush($context = null) {
97 $cacheType = Config
::getVar('cache','cache');
100 // There is no(t yet) selective flushing in memcache;
101 // invalidate the whole thing.
102 $junkCache =& $this->getCache(null, null, null);
106 $filePath = $this->getFileCachePath();
107 $files = glob($filePath . DIRECTORY_SEPARATOR
. 'fc-' . (isset($context)?
$context . '-':'') . '*.php');
108 foreach ($files as $file) {
113 // Nothing necessary.
116 die ("Unknown cache type \"$cacheType\"!\n");