Skip to content

Add support to clear cache by key pattern #2379

Closed
@JosRoseboom

Description

@JosRoseboom

Suppose we have this expensive method that we want to cache:

public MyData getCarBrandDataForCountry(long carbrandId, long countryId){ // my expensive logic }

Now, if some underlying data of a carbrand changes, we want to clear the caches that involves that brand. Similarly, if relevant data of a country changes, we want to clear all the caches that involve that country. Currently, we can only:

  • evict cache by key. We cannot use that, since we only know half of the key
  • clear the entire cache. That would give correct results, but clears a lot of keys unnecessarily.

Currently, clear cache is implemented by clearing all the keys that match the pattern *. Making the pattern a parameter with * as the default would solve the above case. For example, if we would update relevant data for country 42, we could call clearByPattern("*42")

Note: Created this issue to refer to in unit test. PR is on the way.
Edit: Created PR #2380

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions