Paco,

[Cross-posting to the Sling User Group, since I'd like to get this into Sling 
Core if there's interest.]

I just finished up a 6 hour version of the same!  Here's what I did:

* Created a Sling Filter in the "Include" scope that resolves the ResourceType 
for components.
* Checks the properties on the Resource Type to see if it has a "cachable" flag 
and a "cachingStrategy" property.
* Uses either a global or path-based caching strategy, and builds a key that's 
a composite of the appropriate attributes.

The filter then has a reference to an OSGi service that does the actual caching 
-- the interface just specifies a get and a put for the cache.  The "get" 
checks the ttl and doesn't return expired content, and the "put" allows you to 
specify the ttl, which I suppose you could also do as a property on the 
component itself.  The 6 hour version uses a a synchronized map for storage, 
but given that it's an interface, it would be relatively easy to create bundles 
with EhCache, memcache, OSCache and JVM implementations, allowing for swappable 
backends.

Event-based invalidation would be a nice feature, but would obviously require a 
lot of work on both the service and the listener side...

Perhaps we can join forces on github and build something that would be more 
broadly useful?

Dan

On Sep 26, 2011, at 3:10 PM, Przemyslaw Pakulski wrote:


        Hi Dan,
        
        I've implemented some time ago simple caching filter for Sling based on 
OSCache libraries.
        Filter was implemented as configurable OSGi service, which allowed to:
        - enable/disable the filter easily,
        - configure list of sling resource types which are being cached,
        - configure ttl.
        The cache key is calculated based on the resource path and resource 
type.
        
        It worked very well, especially with fixed elements of templates (eg. 
header, footer) and components which using heavy jcr queries.
        Then we started to extend it to add more features like:
        - different levels of caching per component (like statlevel in 
dispatcher),
        - support for jcr events based invalidation, and others
        which made things a bit more complicated :).
        
        Addtionally, because OSCache is dead we also started to reimplement it 
on top of ehcache.
        I'm interested in developing it further, in many scenarios it's very 
usefull. 
        If I can find some time this week I'll try to put simple version on 
github.
        
        Cheers, Paco
        
        --
        Przemo Pakulski
        Solution Architect  / Cognifide
        http://www.cognifide.com <http://www.cognifide.com/> 
        

        -- 
        You received this message because you are subscribed to the Google 
Groups "Day Communique" 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/day-communique?hl=en.
        


Reply via email to