Handling eviction/expiry of composite-keys from GoCache#2106
Merged
zabil merged 1 commit intogocd:masterfrom Apr 13, 2016
Merged
Handling eviction/expiry of composite-keys from GoCache#2106zabil merged 1 commit intogocd:masterfrom
zabil merged 1 commit intogocd:masterfrom
Conversation
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); |
Contributor
There was a problem hiding this comment.
Are these safe from null checks and index checks?
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.