Hi. Microsoft will be releasing the HybridCache library that allows one
to cache data. Are there plans for Couchbase to support the HybridCache? If there are plans, any idea when the library will be available?
Thank you.
Yes, I’m already working on an implementation. We also need it, as we’re currently doing a (very poor) imitation of HybridCache privately. I don’t have an official timeline yet. It will certainly be after the release of .NET 9 in November, though, since until then we won’t have final packages to reference. In case you’re curious, here is the first PR which is laying the groundwork:
couchbaselabs:master
← couchbaselabs:caching-rewrite
opened 07:32PM - 20 Jun 24 UTC
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
-------------
- 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.
3 Likes
system
Closed
December 16, 2024, 11:57am
3
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.