Apparently I can not attach a file, so here is a link to it:
http://thinkof.net/projects/sfProcessCache.class.php.txt
Just save it and remove the .txt extension.
On Jan 26, 2007, at 1:17 PM, Greg Militello wrote:
> Hey all,
> I just made some modifications to sfProcessCache to use sfFileCache
> as a default option if you do not have APC, XCache, or Eaccelerator
> installed.
>
> It is pretty simple, and the only assumption I make it the storage
> path. I set the storage path to:
> sfConfig::get('sf_cache_dir').DIRECTORY_SEPARATOR.'sfProcessCache';
>
> I am not sold on this, due to the fact that you can not change it
> without changing the class, or extending the class. This should be
> refactored back into a YAML file, but I figure this may be useful now
> to you all.
>
> If anyone wants to get this into the symfony repository, feel free.
> Also feel free to adjust anything (such as making the file path user
> configurable).
>
> Comments? Concerns?
>
> Here is the file:
>
>
> >
> <?php
>
> /*
> * This file is part of the symfony package.
> * (c) 2004-2006 Fabien Potencier <[EMAIL PROTECTED]
> project.com>
> *
> * For the full copyright and license information, please view the
> LICENSE
> * file that was distributed with this source code.
> */
>
> /**
> * Allows for data caching, using APC, XCache, Eaccelerator, and
> sfFileCache.
> *
> * @package symfony
> * @subpackage cache
> * @author Fabien Potencier <[EMAIL PROTECTED]>
> * @author Greg Militello <[EMAIL PROTECTED]>
> * @version SVN: $Id$
> */
> class sfProcessCache
> {
> public static function cacher()
> {
> static $cacher = null;
>
> if (!$cacher)
> {
> if (function_exists('apc_store'))
> {
> $cacher = 'apc';
> }
> elseif (function_exists('xcache_set'))
> {
> $cacher = 'xcache';
> }
> elseif (function_exists('ecacher_put'))
> {
> $cacher = 'eaccelerator';
> }
> else
> {
> $cacher = 'sfFileCache';
> }
> }
>
> return $cacher;
> }
>
> public static function filePath()
> {
> static $filePath = null;
>
> if (!$filePath)
> {
> $filePath = sfConfig::get
> ('sf_cache_dir').DIRECTORY_SEPARATOR.'sfProcessCache';
> }
>
> return $filePath;
> }
>
> public static function set($name, $value, $lifeTime = 0)
> {
> switch (self::cacher())
> {
> case 'apc':
> return apc_store($name, $value, $lifeTime);
> break;
> case 'xcache':
> return xcache_set($name, $value, $lifeTime);
> break;
> case 'eaccelerator':
> return eaccelerator_put($name, serialize($value), $lifeTime);
> break;
> case 'sfFileCache':
> $cacher = new sfFileCache (self::filePath());
> $success = $cacher->set ($name, 'sfProcessCache', $value);
> if (sfConfig::get('sf_logging_active'))
> {
> if ($success) {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Successfully set "%s" to cache', $name));
> } else {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Unsuccessfully set "%s" to cache, may not have
> been set', $name));
> }
> }
> return $success;
> break;
> }
>
> return false;
> }
>
> public static function get($name)
> {
> switch (self::cacher())
> {
> case 'apc':
> $value = apc_fetch($name);
> return false === $value ? null : $value;
> break;
> case 'xcache':
> return xcache_isset($name) ? xcache_get($name) : null;
> break;
> case 'eaccelerator':
> return unserialize(eaccelerator_get($name));
> break;
> case 'sfFileCache':
> $cacher = new sfFileCache (self::filePath());
> $success = $cacher->get ($name, 'sfProcessCache');
> if (sfConfig::get('sf_logging_active'))
> {
> if ($success) {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Successfully read "%s" from cache', $name));
> } else {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Unsuccessfully read "%s" from cache, may not
> have been set', $name));
> }
> }
> return $success;
> break;
> }
>
> return null;
> }
>
> public static function has($name)
> {
> switch (self::cacher())
> {
> case 'apc':
> return false === apc_fetch($name) ? false : true;
> break;
> case 'xcache':
> return xcache_isset($name);
> break;
> case 'eaccelerator':
> return null === eaccelerator_get($name) ? false : true;
> break;
> case 'sfFileCache':
> $cacher = new sfFileCache (self::filePath());
> $success = $cacher->has ($name, 'sfProcessCache');
> if (sfConfig::get('sf_logging_active'))
> {
> if ($success) {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Successfully read "%s" from cache', $name));
> } else {
> sfContext::getInstance()->getLogger()->info(sprintf
> ('{sfProcessCache} Unsuccessfully read "%s" from cache, may not
> have been set', $name));
> }
> }
> return $success;
> break;
> }
>
> return false;
> }
> }
>
> I have only tested this with symfony 0.6.3. Your mileage my vary.
>
>
> On Jan 26, 2007, at 12:06 PM, Greg Militello wrote:
>
>>
>> It looks to me like sfProcessCache is only supported with APC, XCache
>> and Eaccelerator. And it does not appear to be part of symfony
>> 0.6.3. I can not upgrade the application I am working on to the
>> latest version yet either.
>>
>> Thoughts? Maybe this is an extension to sfProcessCache that does not
>> require any form of accelerator, and is compatible with 0.6.3?
>>
>>
>>
>>
>> On Jan 17, 2007, at 3:04 AM, Franke Gordon wrote:
>>
>>>
>>> You can use the sfProcessCache
>>>
>>> Example:
>>> http://www.symfony-project.com/snippets/snippet/110
>>>
>>> greetings
>>> Gimler
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [email protected] [mailto:symfony-
>>> [EMAIL PROTECTED] Im Auftrag von Greg Militello
>>> Gesendet: Dienstag, 16. Januar 2007 21:09
>>> An: symfony developers
>>> Betreff: [symfony-devs] Data caching?
>>>
>>>
>>> Hello all,
>>>
>>> I've been looking for a good way to handle this, and it appear
>>> (at least to me) that symfony does not allow caching of data.
>>>
>>> For example I find myself retrieving a data set that I can cache,
>>> but either session variables or request parameters impact what
>>> gets displayed.
>>>
>>> I was thinking an interface to do this would be very easy, just
>>> offer something along these lines:
>>>
>>> <?php
>>>
>>> $cache = new sfDataCache ();
>>>
>>> if (!$cache->retrieve('myDataCacheKey'))
>>> {
>>> $c = new Criteria();
>>> $myData = MyPeer::doSelect($c);
>>>
>>> $cache->set('myDataCacheKey', $myData);
>>> }
>>>
>>> $myData = $cache->retrieve('myDataCacheKey');
>>>
>>> ?>
>>>
>>> I am thinking the set method would have optional parameters for
>>> setting things like cache duration, or flat file storage path.
>>> Also possibly a method to "unset" a cache key.
>>>
>>>
>>> Did I miss something like this in symfony?
>>>
>>>
>>> -Greg
>>>
>>>
>>>
>>>>
>>
>>
>> >>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---