| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/cache/src/lmbCachePersister.interface.php'); 10 lmb_require('limb/core/src/lmbSerializable.class.php'); 11 lmb_require('limb/fs/src/lmbFs.class.php', false); 12 13 @define('LIMB_CACHE_FILE_PREFIX', 'cache_'); 14 15 /** 16 * class lmbCacheFilePersister. 17 * 18 * @package cache 19 * @version $Id: lmbCacheFilePersister.class.php 5945 2007-06-06 08:31:43Z pachanga $ 20 */ 21 class lmbCacheFilePersister implements lmbCachePersister 22 { 23 protected $cache_dir; 24 protected $id; 25 26 function __construct($cache_dir, $id = 'cache') 27 { 28 $this->cache_dir = $cache_dir; 29 $this->id = $id; 30 lmbFs :: mkdir($this->cache_dir); 31 } 32 33 function getId() 34 { 35 return $this->id; 36 } 37 38 function getCacheDir() 39 { 40 return $this->cache_dir; 41 } 42 43 function put($key, $value, $group = 'default') 44 { 45 $file = $this->_getCacheFilePath($group, $key); 46 47 $container = new lmbSerializable($value); 48 lmbFs :: safeWrite($file, serialize($container)); 49 } 50 51 function get($key, $group = 'default') 52 { 53 $file = $this->_getCacheFilePath($group, $key); 54 55 if(!file_exists($file)) 56 return LIMB_CACHE_NULL_RESULT; 57 58 $container = unserialize(file_get_contents($file)); 59 return $container->getSubject(); 60 } 61 62 function flushValue($key, $group = 'default') 63 { 64 $this->_removeFileCache($group, $key); 65 } 66 67 function flushGroup($group) 68 { 69 $this->_removeFileCache($group); 70 } 71 72 function flushAll() 73 { 74 $this->_removeFileCache(); 75 } 76 77 protected function _removeFileCache($group = false, $key = false) 78 { 79 if($key === false) 80 { 81 $files = lmbFs :: find($this->cache_dir, 'f', '~^' . preg_quote($this->_getCacheFilePrefix($group)) . '~'); 82 foreach($files as $file) 83 @unlink($file); 84 } 85 else 86 @unlink($this->_getCacheFilePath($group, $key)); 87 } 88 89 protected function _getCacheFilePrefix($group = false) 90 { 91 return LIMB_CACHE_FILE_PREFIX . ($group ? $group : ''); 92 } 93 94 protected function _getCacheFileName($group, $key) 95 { 96 return $this->_getCacheFilePrefix($group) . '_' . $key . '.cache'; 97 } 98 99 protected function _getCacheFilePath($group, $key) 100 { 101 return $this->cache_dir . '/' . $this->_getCacheFileName($group, $key); 102 } 103 } 104 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 7 05:02:03 2008 | Cross-referenced by PHPXref 0.7 |