Not sure what you mean, but here is an example of checking to see if
something is in the cache, if it is missing, populating the cache and then
returning the object...


I have a @Service CacheMgrHelperBean bean which wraps around my caches and
makes them available to my other beans...


I will say that I think the need to do new Element() is pretty lame. imho,
there should be a cache.put(Object, Object) method.


 @SuppressWarnings("unchecked")

*public* Map<ClipType, List<ClipData>> getShootClips(Long shootId)
*throws*NotFoundException

{

*if* (shootId == *null*)

*throw* *new* NotFoundException("shootId was null");


 Map<ClipType, List<ClipData>> val = *new* HashMap<ClipType,
List<ClipData>>();

Cache cache = *this*.cacheMgrHelper.getShootClipsCache();


 *try*

{

Element element = cache.get(shootId);

*if* (element == *null*)

{

val = *this*.getShootClipsUnCached(shootId);

*if* (val != *null* && val.size() > 0)

cache.put(*new* Element(shootId, val));

}

*else*

{

val = (Map<ClipType, List<ClipData>>)element.getValue();

}

}

*catch* (CacheException ce)

{

*log*.warn(ce);

*try*

{

// Last ditch fallback.

val = *this*.getShootClipsUnCached(shootId);

cache.remove(shootId);

}

*catch* (CacheException ce1)

{

//do nothing...

}

}


 *if* (val == *null*)

*return* Collections.*emptyMap*();


 *return* val;

}

cheers,

jon

On Fri, Dec 18, 2009 at 1:03 PM, Wesley Wu <wumen...@gmail.com> wrote:

> Fortunately I found ehcache's concept is very like Jbosscache with
> regional eviction and cache loader.
> I really did not know ehcache had gone such far in the last two years,
> otherwise I should have evaluated it intensively :p
>
> That means my abstract cache layer won't need too much modification to
> accommodate ehcache.
>
> One of the feature I think ehcache may miss is the searchability of
> cache entries by key or property values.
> I've used Jbosscache Searchable edition (which use lucene) and it did
> some trick for me to search given cache entries and let them go stale.
>
> Any corrections or suggestions?
>
> Thanks very much, Jon.
>
> -Wesley
>
> 2009/12/19 Wesley Wu <wumen...@gmail.com>:
> > Great Jon, you help me to make a critical decision (not to use JBC any
> > more and switch to EHC & Terracotta).
> >
> > I'll give it a shot.
> >
> > -Wesley
> >
> > 2009/12/19 Jon Stevens <latch...@gmail.com>:
> >> yep, i've had several conversations with the cto of terracotta and they
> are
> >> very on the ball about their products.
> >> jon
> >>
> >> On Thu, Dec 17, 2009 at 11:42 PM, Wesley Wu <wumen...@gmail.com> wrote:
> >>>
> >>> Thanks Jon, I'll definitely give terracotta a try.
> >>>
> >>> As far as I know, EHCache was a opensymphony project one or two years
> >>> ago. I noticed that ehcache was acquired by terracotta and became a
> >>> key component of terracotta.
> >>>
> >>> That's great!
> >>>
> >>> -Wesley
> >>>
> >>>
> >>> _______________________________________________
> >>> resin-interest mailing list
> >>> resin-interest@caucho.com
> >>> http://maillist.caucho.com/mailman/listinfo/resin-interest
> >>
> >>
> >> _______________________________________________
> >> resin-interest mailing list
> >> resin-interest@caucho.com
> >> http://maillist.caucho.com/mailman/listinfo/resin-interest
> >>
> >>
> >
>
>
> _______________________________________________
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest
>
_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to