Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache get(...) returns null w/ expired entry and read-through enabled #691

Open
stesie opened this issue Feb 6, 2024 · 0 comments
Open

Comments

@stesie
Copy link

stesie commented Feb 6, 2024

Environment Details

  • MicroStream Version: 08.01.01-MS-GA
  • JDK version: GraalVM 21.0.1+12.1
  • OS: MacOS 14.2.1

Describe the bug

Given a cache with an CreatedExpiryPolicy, read-through enabled and with a cache loader.
Cache is always just accessed via get(K key) method.

Initially cache accesses work fine.

As soon as the cache item has expired the following happens once (in Cache$Default#getValue):

  • isExpired is detected as true ✅
  • the old entry is removed from the cache ✅
  • loadCacheEntry is called to provide a new value ✅
  • expiryForCreation is calculated based on the old item's creation time, hence it immediately is expired again ❓
  • value (returned from the loader) is then overriden to null

Why is this? I see this was introduced by #369, which unfortunately has no (or just private) description.

Subsequent calls to get work fine again, since the old entry was removed and hence next call will just establish a new one.

To Reproduce

Given the following cache configuration

		final MutableConfiguration<String, Object> configuration = new MutableConfiguration<>();
		configuration.setReadThrough(true);
		configuration.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SomeCustomCacheLoader()));
		configuration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_DAY));
		configuration.setStoreByValue(false);

Then get("whatever")... wait for the expiry period to have passed ... then get("whatever") again.

Expected behavior

Should return the actual value from the loader.

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

No branches or pull requests

1 participant