Skip to content

[BUG?] LocalCacheExpiration (L1) Ignoring assigned value when L2 cache disabled (HybridCache) #498

@TheSpookyElectric

Description

@TheSpookyElectric

I'm seeing a strange behavior when using HybridCache and I'm not sure if it's an oversight on my part. I want to store somthing long lived only L1, so I disable L2, and set LocalCacheExpiration to 12 hours. However, the expiry is only set to 30 seconds regardless.

[18:05:06 INF] FUSION [N=FusionCache I=0HNDFFKLBN5RI] (O=0HNDFFKLBN5RO K=testkey): GetOrSetAsync return FE(M)[T=2025-06-19T22:05:06.964620, LEXP=2025-06-19T22:05:36.964617][]

To Reproduce

                String? testString = await _hybridCache.GetOrCreateAsync("testkey", async cancellationToken =>
                {
                        return "some value";
                },
                new()
                {
                    LocalCacheExpiration = TimeSpan.FromHours(12),
                    Flags = HybridCacheEntryFlags.DisableDistributedCache
                });

Hitting this code performs as expected, except that every 30 seconds (instead of 12 hours), it heads into the Create path.

Now, If I also set L2 to 12 hours and remove the flag, then both L1 and L2 seem to get the proper 12 hours. L2 is obvious and visible in redis, and for L1, I inspected the '_mca' inside of InnerFusionCache and it was present beyond the 30 second default.

[18:32:06 INF] FUSION [N=FusionCache I=0HNDFFTEGKDQ0] (O=0HNDFFTEGKDQP K=testkey): GetOrSetAsync return FE(M)[T=2025-06-19T22:19:40.114490, LEXP=2025-06-20T10:19:40.114347][]

Expected behavior

When disabling L2, and setting a value on L1 should, that value should be respected.

Versions

I've encountered this issue on:

  • FusionCache version - 2.3.0
  • .NET version - 9
  • OS version - Win11
  • Redis - 7.4.2

Additional context

        builder.Services.AddFusionCache()
            .WithSystemTextJsonSerializer()
            .WithDistributedCache(new RedisCache(new RedisCacheOptions { Configuration = StringConstants.REDIS_CACHE_URL }))
            .AsHybridCache();

It may not even be a FusionCache issue in the end, but here we are

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions