Page 1 of 1

Cache invalidation problem

Posted: Wed Feb 01, 2017 1:35 pm
by karim.hj
Hello Broadleaf' users !

I am trying to understand a strange behavior I have with cache invalidation with the Broadleaf demo.
When I modify product directly in DB, product page displays randomly the cached value or the new value stored in db until the cache expires.
browser: firefox/chrome ( cache is disabled)
demoSite: develop-5.0.x
db: mysql5

There are the steps to reproduce it.

1) Increase CACHE on site
I have increased the timeToLiveSeconds="360" in bl-override-ehcache.xml for all caches.

Code: Select all

        <cacheEventListenerFactory class="org.broadleafcommerce.common.cache.engine.HydratedCacheEventListenerFactory"/>

cachejmx.png (45.62 KiB) Viewed 4777 times

2) GET Product from Api ENDPOINT

Code: Select all

curl -H "Content-Type: application/json" http://localhost:8080/api/v1/catalog/product/

Code: Select all

{"id":1,"name":"Sudden Death Sauce","longDescription":"As my Chilipals know, ...",...,"manufacturer":"Blair's"]}

As expected I get the value from the database which is "manufacturer":"Blair's"
The value is now stored in cache. ( I have just previously invalidated the cache just to be sure)

3) Change product's value in database

I change quickly the value of manufacturer directly into the database

Code: Select all

curl -H "Content-Type: application/json" http://localhost:8080/api/v1/catalog/product/1

And i still get "manufacturer":"Blair's" which is perfectly normal as the value is retrieved from the cache.

But when I go to the product page :
It displays randomly "Blair's BBB" or "Blair's" as product's manufacturer property value as I am reloading the page !! (ctrl + F5)
I would expect to get the same value equals to the json value ("blair's") until the cache expires.

Blair's bbb
screenshot-bbb.png (247.3 KiB) Viewed 4777 times

Blair expected value
screenshot-blair.png (109.47 KiB) Viewed 4777 times

5) Cache expiration
After 360 seconds ( = cache expiration or cache invalidation via), everything goes back to normal: the new value ( "Blair's BBB") is always returned in json or browser.

My question is :
How to explain the behavior in step 4. Is it normal ? Is there an other cache mechanism involved ?

Thanks !

Re: Cache invalidation problem

Posted: Tue Jul 25, 2017 10:37 am
by phillipuniverse
I can't really explain your results in step 4 either, especially if you just have a single application server. If you have multiple, since the cache is just a local, per-node cache, then you could be hitting different servers that have the results cached differently. Also possible that the browser could be caching it? If you do a hard refresh (ctrl + shift + r) then it also wipes the browser cache.

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.