v1.3.0
♊ Auto-Clone (docs)
In general is never a good idea to mutate data retrieved from the cache: it should always be considered immutable/readonly.
To see why, read more in the docs.
Not all the scenarios where mutating a piece of data we got from the cache are necessarily wrong though, as users may have a particular use case where that may be needed, and ideally they should be abe to do that in an easy (and optimized!) way, by following the tried and true "it just works" mindset.
With Auto-Clone this is now possible.
A couple of details:
- it just works, out of the box
- is easy to use
- doesn't require extra coding/setup (it's just a new
EnableAutoClone
option) - uses existing code infrastructure (eg: IFusionCacheSerializer)
- has granular control on a per-entry basis
- is performant (as much as possible)
Thanks to community users @JarrodOsborne and @kzkzg !
See here for the original issue.
💣 Fail-Safe Without Exceptions (docs)
Currently the way to activate fail-safe is for a factory to throw an exception.
This makes sense, since the whole point of fail-safe is to protect us when an error occurs while executing a factory.
But there may be other ways to do it, for example by using a variation of the Result Pattern or similar approaches, in which throwing an exception is not necessary.
This is now possible thanks to the new Fail(...)
method on the FusionCacheFactoryExecutionContext<TValue>
type, which we can access when executing a factory.
A quick example:
var productResult = await cache.GetOrSetAsync<Result<Product>>(
$"product:{id}",
async (ctx, ct) =>
{
var productResult = GetProductFromDb(id);
if (productResult.IsSuccess == false)
{
return ctx.Fail(productResult.Error);
}
return productResult;
},
opt => opt.SetDuration(duration).SetFailSafe(true)
);
Thanks to community user @chrisbbe that noticed it!
See here for the original issue.
🧙♂️ Adaptive Caching on errors (docs)
Previously it was not possible to use adaptive caching when an error occurred during a factory execution.
This was usually not a big issue, but it left a particular edge case not fully uported: selectively enabling/disabling fail-safe on errors.
Now this is possible, in the usual unified way.
Thanks to community user @cmeyertons for spotting it, and for creating the PR that solved it.
See here for the original issue.
📦 More granular (and less) dependencies with multi-targeting
Thanks to a note by community user @thompson-tomo FusionCache now multi-targets different .NET vesions.
This was not needed per-se, but by doing it FusionCache can now have less dependencies for some TFMs.
See here for the original issue.
🚀 Better perf for FusionCacheProvider (docs)
Community user @0xced contributed with a PR that improved the performance of FusionCacheProvider, used with Named Caches.
See here for the original PR.
⚠️ Update dependencies for CVE-2024-30105
Communicty user @dependabot (😅) noticed CVE-2024-30105 and promptly bumped the referenced version of the System.Text.Json package.
Note that this is only related to the package ZiggyCreatures.FusionCache.Serialization.SystemTextJson.
✅ Better tests
Some tests have been added for each new feature, and overall better snapshot tests.
📕 Docs
Updated some docs with the latest new things.