ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2.01k stars 579 forks source link

Cache Invalidation Performance #3137

Open mmonetha-sobis opened 1 year ago

mmonetha-sobis commented 1 year ago

Hi, at my company, we've encountered some issues connected to our cache invalidation logic.

For each cache entry that should be invalidated

We refactor our implementation that

Unfortunately the performance appears to be unchanged.

We then started checking the ehcache code base and realized that both operations (remove and removeAll) also deserialize the cache entry's value everytime either operation is called.

  1. Are our observations correct? Doesn't it matter - performance wise, wether one iterates over the cache entries himself and removes them via cache.remove() vs gathering all keys beforehand and removing them via cache.removeAll()
  2. Is there a way to invalidate cache entries without deserializing the cache entry's value?
chrisdennis commented 1 year ago

Currently it will be more efficient to do this via external iteration and calls to remove(K) as this will avoid unnecessary deserializations. I just created a draft PR that makes this true for removeAll(...) as well (#3138) but it needs some close review/checking before it can be merged.

nikowitt commented 1 year ago

Having an iteration like

for (Cache.Entry<ICustomCacheKey, Serializable> entry : cache) {
                if (entry != null) {
                    ICustomCacheKey cachedKey = entry.getKey();
                    LOGGER.trace("Iterating over {} on {}", cachedKey, cacheName);
                    if (cachedKey.matches(givenKey)) {
                        cache.remove(cachedKey);
                        LOGGER.debug("'{}' was removed from cache '{}'.", givenKey, cacheName);
                    }
                }

            }

also deserializes values. Can you provide more details about the external iteration you had in mind?

nikowitt commented 10 months ago

Hi Chris, is there some update on this topic?

Thanks in advance!

AnnColo commented 6 months ago

Hi Chris, we are again stumbling across this issue, are there any news regarding our original question?