ConcurrentCaching 0.2.2
dotnet add package ConcurrentCaching --version 0.2.2
NuGet\Install-Package ConcurrentCaching -Version 0.2.2
<PackageReference Include="ConcurrentCaching" Version="0.2.2" />
<PackageVersion Include="ConcurrentCaching" Version="0.2.2" />
<PackageReference Include="ConcurrentCaching" />
paket add ConcurrentCaching --version 0.2.2
#r "nuget: ConcurrentCaching, 0.2.2"
#:package ConcurrentCaching@0.2.2
#addin nuget:?package=ConcurrentCaching&version=0.2.2
#tool nuget:?package=ConcurrentCaching&version=0.2.2
concurrent-memory-cache
A simple wrapper over MemoryCache to prevent concurrent cache missing.
Purpose
The Microsoft MemoryCache API provides the ability to cache locally, however it does not guarantee the atomicity when multiple threads call GetOrCreate()
with the same entry (at the moment this was written), which can lead to multiple cache missing and duplicated data fetching.
How it works
It was implemented based on the same idea used by ConcurrentDictionary, which divides the Hashmap into a fixed number of segments (16 by default). Each of them is protected by a segment lock. Write operations that fall into the same segment are sequentialized, while write operations falling into different segments are handled concurrently. All read operations are lock-free.
How to use
Install package:
dotnet add package ConcurrentCaching
Inject caching service:
services.AddMemoryCache(options => { //... Setup e.g. max cache limit for LRU }); services.AddSingleton<IConcurrentMemoryCache, ConcurrentMemoryCache>();
Fetch data from cache:
var item = cache.GetOrCreate<TItem>("<key>", entry => { // Fetch data from elsewhere and return it ... }); var item = await cache.GetOrCreateAsync<TItem>("<key>", async entry => { // Fetch data from elsewhere and return it ... });
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.