The current implementation of IDistributedCache provided by Couchbase.Extensions.Caching doesn't properly follow the IDistributeCache contract, especially around sliding expirations. This can cause unexpected behaviors, especially if used in combination with other NuGet packages that expect the contract to be followed.
Modifications
Upgrade to SDK 3.5.2 which is required for XATTR transcoder support and more performant LookupIn/MutateIn operations.
Use XATTR to store metadata about the cache item, including the sliding expiration. This also requires using a special serializer and transcoder, allowing custom serializers and transcoders to apply to most types but letting us control byte[] and CacheMetadata cases.
Push the Couchbase expiration using TouchAsync based on the persisted sliding expiration.
Remove extension methods for IDistributedCache, users who want to use typed serialization should inject or typecast to ICouchbaseCache to get the feature.
Implement a default sliding expiration, with a default of 20 minutes, when caching items with no expiration at all provided. This is consistent with the SQL distributed cache provider. Also, remove the LifeSpan from options.
Make CouchbaseCache an internal implementation detail, only exposing ICouchbaseCache.
Always return the same instance of CouchbaseCache when DI requests arrive for ICouchbaseCache or IDistributeCache, previously they were different singletons.
Use the new TimeProvider type (with back-compat package) to help with testability.
Use options to inject the bucket/scope/collection names, rather than purely relying on inconsistent DI behaviors. The consumer may still register their own ICouchbaseCacheCollectionProvider which will take precedence.
Hide CouchbaseCacheOptions.Value as an explicit interface implementation
Use NativeAOT/trim compatible methods for registering the cache bucket/collection and mark the package as AOT-compatible when targeting .NET 8.
Rewrite Sessions unit tests to not use Caching internals and use mocks instead.
Results
Generic consumers of IDistributedCache will now function as expected when the backing implementation is Couchbase, rather than having unusual behaviors (especially around sliding expiration).
Initial setup on DI is simpler and more consistent. In particular, it's now much easier to use a scope/collection.
Confusing extension methods on IDistributeCache that may fail at runtime are no longer present.
NativeAOT support will light up when the main SDK gets support.
Breaking Changes
This is a breaking change that will require a SemVer major version bump. The API surface has both source and binary breaking changes, and the semantic behaviors are now different.
CouchbaseCacheOptions.Value is now hidden
CouchbaseCacheOptions.LifeSpan is removed
CouchbaseCache class is now internal and in a new namespace
CouchbaseCacheExtensions class is removed
CouchbaseCacheServiceCollectionExtensions overload with a bucketName is now marked obsolete.
ICouchbaseCache.CollectionProvider, ICouchbaseCache.Options, and ICouchbaseCache.GetLifetime are removed.
ICouchbaseCacheCollectionProvider no longer explicitly implements GetCollectionAsync, it now inherits from INamedCollectionProvider.
Motivation
The current implementation of IDistributedCache provided by Couchbase.Extensions.Caching doesn't properly follow the IDistributeCache contract, especially around sliding expirations. This can cause unexpected behaviors, especially if used in combination with other NuGet packages that expect the contract to be followed.
Modifications
Results
Breaking Changes
This is a breaking change that will require a SemVer major version bump. The API surface has both source and binary breaking changes, and the semantic behaviors are now different.