| 1 | <?php␊ |
| 2 | /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */␊ |
| 3 | /*␊ |
| 4 | # ***** BEGIN LICENSE BLOCK *****␊ |
| 5 | # This file is part of Plume Framework, a simple PHP Application Framework.␊ |
| 6 | # Copyright (C) 2001-2007 Loic d'Anterroches and contributors.␊ |
| 7 | #␊ |
| 8 | # Plume Framework is free software; you can redistribute it and/or modify␊ |
| 9 | # it under the terms of the GNU Lesser General Public License as published by␊ |
| 10 | # the Free Software Foundation; either version 2.1 of the License, or␊ |
| 11 | # (at your option) any later version.␊ |
| 12 | #␊ |
| 13 | # Plume Framework is distributed in the hope that it will be useful,␊ |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of␊ |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the␊ |
| 16 | # GNU Lesser General Public License for more details.␊ |
| 17 | #␊ |
| 18 | # You should have received a copy of the GNU Lesser General Public License␊ |
| 19 | # along with this program; if not, write to the Free Software␊ |
| 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA␊ |
| 21 | #␊ |
| 22 | # ***** END LICENSE BLOCK ***** */␊ |
| 23 | ␊ |
| 24 | /**␊ |
| 25 | * Cache class.␊ |
| 26 | *␊ |
| 27 | * You should not use this class directly, but one of the subclasses␊ |
| 28 | * implementing a given engine. This is done automatically when using␊ |
| 29 | * the factory. It will use the engine defined by the 'cache_engine'␊ |
| 30 | * configuration variable.␊ |
| 31 | *␊ |
| 32 | * Default timeout in seconds is defined by the 'cache_timeout'␊ |
| 33 | * configuration variable.␊ |
| 34 | *␊ |
| 35 | * <pre>␊ |
| 36 | * $cache = new Pluf_Cache::factory();␊ |
| 37 | * if (null === ($foo=$cache->get('my-key'))) {␊ |
| 38 | * $foo = run_complex_operation();␊ |
| 39 | * $cache->set('my-key', $foo);␊ |
| 40 | * }␊ |
| 41 | * return $foo;␊ |
| 42 | * </pre>␊ |
| 43 | *␊ |
| 44 | * The value to be stored in the cache must be serializable.␊ |
| 45 | *␊ |
| 46 | * @see http://www.php.net/serialize␊ |
| 47 | */␊ |
| 48 | class Pluf_Cache␊ |
| 49 | {␊ |
| 50 | /**␊ |
| 51 | * Factory.␊ |
| 52 | *␊ |
| 53 | * @return Pluf_Cache_* Cache object␊ |
| 54 | */␊ |
| 55 | public static function factory()␊ |
| 56 | {␊ |
| 57 | if (false === ($engine=Pluf::f('cache_engine', false))) {␊ |
| 58 | throw new Pluf_Exception_SettingError('"cache_engine" setting not defined.');␊ |
| 59 | }␊ |
| 60 | if (!isset($GLOBALS['_PX_Pluf_Cache-'.$engine])) {␊ |
| 61 | $GLOBALS['_PX_Pluf_Cache-'.$engine] = new $engine();␊ |
| 62 | } ␊ |
| 63 | return $GLOBALS['_PX_Pluf_Cache-'.$engine];␊ |
| 64 | }␊ |
| 65 | ␊ |
| 66 | /**␊ |
| 67 | * Set a value in the cache.␊ |
| 68 | *␊ |
| 69 | * @param string Key to store the information␊ |
| 70 | * @param mixed Value to store␊ |
| 71 | * @param int Timeout in seconds (null)␊ |
| 72 | * @return bool Success␊ |
| 73 | */␊ |
| 74 | public function set($key, $value, $timeout=null)␊ |
| 75 | {␊ |
| 76 | throw new Pluf_Exception_NotImplemented();␊ |
| 77 | }␊ |
| 78 | ␊ |
| 79 | /**␊ |
| 80 | * Get value from the cache.␊ |
| 81 | *␊ |
| 82 | * @param string Key to get the information␊ |
| 83 | * @param mixed Default value to return if cache miss (null)␊ |
| 84 | * @param mixed Stored value or default␊ |
| 85 | */␊ |
| 86 | public function get($key, $default=null)␊ |
| 87 | {␊ |
| 88 | throw new Pluf_Exception_NotImplemented();␊ |
| 89 | }␊ |
| 90 | }␊ |
| 91 | |