Page 1 of 1

How to Clear Ehcache(HydratedCache) elements

Posted: Mon Dec 10, 2012 12:40 pm
by knayirpalusac
How Do I clear Ehcache data from broadleaf commerce?

I have updated some data in the database related to sku and it is not getting reflected.

I am actually interested in the below ehcache element

Code: Select all

    <cache
       name="blStandardElements"
       maxElementsInMemory="1"
       eternal="false"
       overflowToDisk="false"
        timeToLiveSeconds="1">
       <cacheEventListenerFactory class="org.broadleafcommerce.common.cache.engine.HydratedCacheEventListenerFactory"/>
    </cache>


I am not very clear about the HydratedCache but it looks to me like that is holding the cached elements. Is there a way to clear this cache dynamically rather than restarting the instance?

Re: How to Clear Ehcache(HydratedCache) elements

Posted: Mon Nov 14, 2016 9:57 am
by ananich
Have you found a way to do this?

Re: How to Clear Ehcache(HydratedCache) elements

Posted: Tue Jul 25, 2017 3:29 pm
by phillipuniverse
If you get a handle to the cache from somewhere you can clear it out. Here is an example controller that could clear out the blStandardElements cache:

Code: Select all

@RestController
public class CacheClearer {
    @RequestMapping(value = "/cache/clear", method = RequestMethod.POST)
    public String clearCache(@RequestParam(name = "cacheRegion") String cacheRegion) {
        CacheManager.getInstance().getCache(cacheRegion).removeAll();
        return "Success";
    }
}


With that you could send a POST to /cache/clear?cacheRegion=blStandardElements to clear out the cache. Might not be the best thing to expose, but the important part is to get access to the cache use CacheManager.getInstance().getCache("blStandardElements").

In the commercial version of Broadleaf we do automatic cache invalidation for ehcache as well as Solr.

The Broadleaf forums are being retired as a readonly archive of questions. For active discussions and questions, check out the broadleaf-commerce tag on Stack Overflow which is actively monitored by the Broadleaf team.