microstream-one / microstream

High-Performance Java-Native-Persistence. Store and load any Java Object Graph or Subgraphs partially, Relieved of Heavy-weight JPA. Microsecond Response Time. Ultra-High Throughput. Minimum of Latencies. Create Ultra-Fast In-Memory Database Applications & Microservices.
https://microstream.one/
Eclipse Public License 2.0
560 stars 44 forks source link

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

Open stesie opened 9 months ago

stesie commented 9 months ago

Environment Details

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):

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.