Ahh, very true. There is a built-in GlobalCache service in Turbine (2.2, at
least) which may be useful to you (it supports expiration but not to disk,
etc). I guess it depends what you need it for.

Global caches can have some drawbacks when you want data tied to a
particular session...

If you decide to use the GlobalCache service, you might find these static
accessors handy:


-----------
package com.genix.property.utils;

import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.cache.CachedObject;
import org.apache.turbine.services.cache.GlobalCacheService;
import org.apache.turbine.services.cache.ObjectExpiredException;

/**
 * Static accessors to the turbine GlobalCacheService.
 * 
 * @author Greg Kerdemelidis (greg at genixsystems dot com)
 */
public class CacheUtils
{
        /**
         * Get an object from the Turbine global cache service.
         * 
         * @param key The key for the desired object.
         * @return Object that was stuffed into the cache.
         * @throws ObjectExpiredException when the Object has expired, or
does not exist.
         * @throws InstantiationException when the GlobalCacheService cannot
be located.
         */
        public static Object get(String key)
                throws ObjectExpiredException, InstantiationException
        {
                /*
                 * Look for the item in the cache.
                 * If it doesn't exist or the item is stale,
                 * the cache will throw an exception.
                 */
                GlobalCacheService gs =
        
(GlobalCacheService)TurbineServices.getInstance().getService(
                                GlobalCacheService.SERVICE_NAME);

                return gs.getObject(key).getContents();
        }

        /**
         * Puts an object in the Turbine global cache.
         * 
         * @param key The key for the data.
         * @param o The data.
         * @param duration How long before the data gets expired (in
milliseconds)
         * @throws InstantiationException when the GlobalCacheService cannot
be located.
         */
        public static void put(String key, Object o, long duration)
        throws InstantiationException
        {
                GlobalCacheService gs =
(GlobalCacheService)TurbineServices.getInstance().getService(GlobalCacheServ
ice.SERVICE_NAME);
                gs.addObject(key,new CachedObject(o,duration));
        }
}

-----------

> -----Original Message-----
> From: Nathaniel Reed [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 30 October 2003 11:33 a.m.
> To: Turbine Users List; [EMAIL PROTECTED]
> Subject: Re: persisting objects in context across requests
> 
> Hi, you might be interested in a technique we borrowed from a JavaWorld
> article:
> 
> http://www.javaworld.com/javaworld/jw-06-1999/jw-06-cooltools.html
> 
> It's a "cache" that can be used to conveniently store objects in-between
> HTTP requests.  We easily extended this caching mechanism to write out
> the objects to disk when they expire, and to retrieve them from disk if
> they are not in the cache.
> 
> Nate
> 
> brian wrote:
> 
> >Hello,
> >
> >       Is there a way to save an object in the
> >(org.apache.velocity.context.Context) for longer than the current page
> >request, so it may retrieved from a different template page later?
> >
> >
> >
> >Brian A
> >
> >
> >
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to