v0.20.0-preview2
Pre-release⚠ PRE-RELEASE
This is a pre-release of FusionCache, so please be aware that although it contains some shiny new stuff (see below), it is also subject to change before the final release.
Having said that, you should also know that this version is already very polished, the api design surface area well modeled, performance-tuned, with full xml-docs and it has all the bells and whistles of a normal release.
ℹ NOTE: if you are updating from a previous version, please read here.
Ok, enough with the warnings: let's talk about the features 🎉
👷♂️ Added Builder Pattern support
There's now a really easy to use and flexible fluent API that supports the builder pattern.
This allows a nice modular setup of FusionCache when using dependency injection, with the ability to add components and configure them with a couple of keystrokes, like:
services.AddFusionCache()
.WithSerializer(
new FusionCacheSystemTextJsonSerializer()
)
.WithDistributedCache(
new RedisCache(new RedisCacheOptions()
{
Configuration = "..."
})
)
.WithBackplane(
new RedisBackplane(new RedisBackplaneOptions()
{
Configuration = "..."
})
)
;
NOTE: The api surface has changed a little bit from v0.20.0-preview1.
Thanks to the community member @aKzenT for the invaluable help with the design discussion.
See here for the issue.
See here for the docs.
📛 Added Named Caches support
FusionCache now natively support multiple named caches via dependency injection, thanks to the new IFusionCacheProvider
interface/service.
This makes it easy to register and retrieve different caches, potentially with different underlying caching storage (but not necessarily) and different configurations.
This is even easier thanks to the aforementioned Builder Pattern support, like this:
// USERS CACHE
services.AddFusionCache("UsersCache")
.WithDefaultEntryOptions(opt => opt
.SetDuration(TimeSpan.FromSeconds(10))
)
;
// PRODUCTS CACHE
services.AddFusionCache("ProductsCache")
.WithDefaultEntryOptions(opt => opt
.SetDuration(TimeSpan.FromSeconds(30))
.SetFailSafe(true, TimeSpan.FromMinutes(10))
)
;
Then you can depend on an IFusionCacheProvider
service and easily ask to it for a certain cache with a GetCache("MyCache")
call.
For example in an mvc controller you can go like this:
public class HomeController : Controller
{
IFusionCache _usersCache;
IFusionCache _productsCache;
public HomeController(IFusionCacheProvider cacheProvider)
{
_productsCache = cacheProvider.GetCache("ProductsCache");
_usersCache = cacheProvider.GetCache("UsersCache");
}
public IActionResult Product(int id)
{
_productsCache.GetOrDefault<Product>($"product:{id}");
// ...
}
}
And again, thanks to the community member @aKzenT for the invaluable help with the design discussion here, too.
See here for the issue.
See here for the docs.
🆕 Added CacheKeyPrefix
option
Since there's now native support for multiple named caches, I'm currently playing with the idea of adding support for a CacheKeyPrefix
option, that would be added in front of any cache key you specify with a certain FusionCache instance. This can be helpful to avoid cache key collisions when working with multiple named caches all sharing the same underlying caching storage mechanism (eg: memory, Redis, MongoDB, etc).
♾ Handle Infinity
There's now native support for infinite expirations, with specific optimizations in the code to avoid exceptions and for better perf.
See here for more.
📜 Custom Plugins Log Levels
Two new options have been added to control the level for plugins info/error log entries.
See here for more.