Skip to content

Handling eviction/expiry of composite-keys from GoCache#2106

Merged
zabil merged 1 commit intogocd:masterfrom
jyotisingh:composite_cache_expiry
Apr 13, 2016
Merged

Handling eviction/expiry of composite-keys from GoCache#2106
zabil merged 1 commit intogocd:masterfrom
jyotisingh:composite_cache_expiry

Conversation

@jyotisingh
Copy link
Contributor

@jyotisingh jyotisingh commented Apr 13, 2016

When a composite key is saved to cache, there are two entries created in the cache. One for the composite-key itself containing the actual value. Another entry to keep track of all sub-keys for a given parent. When a parent cache entry is explicitly removed, the corresponding caches for subkeys are removed as well. When a subkey is explicitly removed, the sub-key list with the parent cache entry is updated as well. However, when a sub-key entry gets evicted from the cache when it gets full or when it expires, the parent cache entry wasn't updated. This commit fixes that.

There is a second part of it which is addressed by #2113, which takes care of evicting the subkey-entries from cache when the parent entity is evicted or expired.

When a composite key is saved to cache, there are two entries created in the cache. One for the composite-key itself containing the actual value. Another entry to keep track of all sub-keys for a given parent. When a parent cache entry is explicitly removed, the corresponding caches for subkeys are removed as well. When a subkey is explicitly removed, the sub-key list with the parent cache entry is updated as well. However, when a sub-key entry gets evicted from the cache when it gets full or when it expires, the parent cache entry wasn't updated. This commit fixes that.

public void removeCompositeKeyFromParentCache(String key) {
if (key.contains(SUB_KEY_DELIMITER)) {
String[] parts = StringUtils.splitByWholeSeparator(key, SUB_KEY_DELIMITER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these safe from null checks and index checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentKey cannot be null as that is one of the keys in the map maintained by ehcache, so it would fail at the time of insertion itself. childKey would be null if the key used in the cache is "parent!#$#!", but then it would lead to other cache related errors as all such composite caches will have the same key. Moreover StringUtils.splitByWholeSeparator("parent!_#$#_!", "!_#$#_!") returns

result = {java.lang.String[2]@1305} 
 0 = "parent"
 1 = ""

so we should be ok I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants