PS.Memory.FileCache
1.6.0
dotnet add package PS.Memory.FileCache --version 1.6.0
NuGet\Install-Package PS.Memory.FileCache -Version 1.6.0
<PackageReference Include="PS.Memory.FileCache" Version="1.6.0" />
paket add PS.Memory.FileCache --version 1.6.0
#r "nuget: PS.Memory.FileCache, 1.6.0"
// Install PS.Memory.FileCache as a Cake Addin #addin nuget:?package=PS.Memory.FileCache&version=1.6.0 // Install PS.Memory.FileCache as a Cake Tool #tool nuget:?package=PS.Memory.FileCache&version=1.6.0
Branch | Build status | Package |
---|---|---|
Master | ||
CI |
Description
It is simple in-process file cache implementation inherited from standard ObjectCache class. FileCache is thread safe (supports multithread/multiprocessing parallel cache processing).
Capabilities
Support
- AbsoluteExpirations: The ability to automatically remove cache entries at a specific date and time.
- SlidingExpirations: The ability to automatically remove cache entries that have not been accessed in a specified time span.
- CacheRegions: The ability to partition its storage into cache regions, and supports the ability to insert cache entries into those regions and to retrieve cache entries from those regions.
- InMemoryProvider: Current implementation uses [MemoryCache] internally as fast proxy.
Not support
- CacheEntryChangeMonitors: The ability to create change monitors that monitor entries.
- CacheEntryRemovedCallback: Can raise a notification that an entry has been removed from the cache.
- CacheEntryUpdateCallback: Can raise a notification that an entry is about to be removed from the cache. This setting also indicates that a cache implementation supports the ability to automatically replace the entry that is being removed with a new cache entry.
How to use
Generic usage is the same as MemoryCache usage.
To setup cache location use DefaultRepository as FileCache constructor parameter. Default location is <app folder>\Cache\
using (var repository = new DefaultRepository(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))))
{
var cache = new FileCache(repository))
//...
}
Settings
Current implementation has several logically separated parts that can be changed or overridden.
IRepository
Encapsulates all IO operations. Library contains default implementation DefaultRepository. All methods in default implementation are virtual so can be overridden.
Cache location
Cache location can be changed via constructor parameter.
Key and Region name sanitizing
To enable/disable cache keys and regions sanitizing use sanitizeNames constructor parameter. Default value is true.
Cleanup settings
Default implementation supports automatic repository cleaning within a fixed period of time (2 seconds by default) on instance dispose and via manual DefaultRepository.Cleanup()
call.
Clean operation means delete all files that were marked as deleted or expired.
To prevent file access issues there is delay options (5 seconds by default) which means file is allowed for deletion only after specified period.
var cleanupSettings = new CleanupSettings //Default settings defined in static CleanupSettings.Default property
{
GuarantyFileLifetimePeriod = TimeSpan.FromSeconds(5),
CleanupPeriod = TimeSpan.FromSeconds(2)
};
using (var repository = new DefaultRepository(cleanupSettings: cleanupSettings))
{
var cache = new FileCache(repository)
//...
}
Also CleanupSettings.Infinite
static property can be used to disable cleanup functionality.
IMemoryCacheFacade
Fast proxy operations. DefaultMemoryCacheFacade you can configure internal items lifetime period via constructor parameter. Default value is 10 minutes.
IDataSerializer
Controls how cache item will be serialized and deserialized. DefaultDataSerializer have 2 stage serialization:
- Serialize CacheItem value (using BinaryFormatter)
- Serialize CacheItem itself (using binary reader and writer).
Cache values serialization can be easily modified.
Json data serialization/deserialization using Json.NET
class JsonDataSerializer : DefaultDataSerializer
{
protected override object DeserializeData(Type type, byte[] data)
{
var json = Encoding.UTF8.GetString(data);
return JsonConvert.DeserializeObject(json, type);
}
protected override byte[] SerializeData(Type type, object data)
{
var json = JsonConvert.SerializeObject(data);
return Encoding.UTF8.GetBytes(json);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.1
- No dependencies.
-
net5.0
- System.Runtime.Caching (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.