Hi Jan,

What if my goal is to remove from the cache a page w/a specific selector 
though?  For example, if I have:

/foo/bar.one.html
/foo/bar.two.html
...

I have a case where I actually only want to remove /foo/bar.two.html from 
cache.  If I understand what you are saying it sounds like I should not use the 
UUID because that would remove all variants of the page.  I wrote some code 
that seems to work but it mostly ignores locale, parameters and is tied to a 
specific cache implementation.  Less than ideal but I couldn't find any more 
general methods in Magnolia to help.

public static void flushByHandle(String uri) {

    String localeString = null;
    Map<String, String> params = new HashMap<String, String>();
    String serverName = null;

    if (MgnlContext.isWebContext()) {
        localeString = MgnlContext.getWebContext().getLocale().toString();
        serverName = MgnlContext.getWebContext().getRequest().getServerName();
    }

    DefaultCacheKey key = new DefaultCacheKey(uri, serverName, localeString, 
params);

    CacheModule cacheModule = 
ModuleRegistry.Factory.getInstance().getModuleInstance(CacheModule.class);
    CacheFactory factory = cacheModule.getCacheFactory();

    Collection<CacheConfiguration> cacheConfigs = 
cacheModule.getConfigurations().values();

    for (CacheConfiguration config : cacheConfigs) {
        final Cache cache = factory.getCache(config.getName());
        cache.remove(key);
    }
}

Tom

On Nov 1, 2010, at 3:12 PM, Jan Haderka wrote:

> I'd suggest you retrieve the page by path to find out its uuid and then 
> remove it from cache using the methods for removing cache items by uuid.
> 
> The reason is that there might be multiple variants of this page in the cache 
> - with or w/o selectors, with different locales, with different parameters or 
> headers, etc ... you get the picture. While you can possibly construct the 
> key for the cache item from the url used to create such a cache entry, there 
> are way too many other variants to make it reliable.
> I don't have the code in front of me right now, but since some recent version 
> there are even commands you can call with the uuid to remove the cache 
> entries, so you can run it from scheduled task or as part of the workflow.
> 
> HTH,
> Jan
> 
> On Oct 29, 2010, at 3:39 PM, Thomas Duffey wrote:
> 
>> 
>> Hi Everyone,
>> 
>> Is it possible to programmatically remove items from the Magnolia cache?  In 
>> particular, I would like to programmatically remove pages from cache when 
>> certain things occur.  I found some code about removing items from cache by 
>> UUID but in some cases I will only know the page handle and it will include 
>> a selector, e.g.,
>> 
>> /foo/bar.one.html
>> /foo/bar.two.html
>> etc.
>> 
>> Does Magnolia even cache URLs with selectors separately and is there a way 
>> to remove just one of them from the cache if I know the handle?

--
Tom Duffey
[email protected]
414-915-3915





----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to