Lyo.Cache
1.0.6
dotnet add package Lyo.Cache --version 1.0.6
NuGet\Install-Package Lyo.Cache -Version 1.0.6
<PackageReference Include="Lyo.Cache" Version="1.0.6" />
<PackageVersion Include="Lyo.Cache" Version="1.0.6" />
<PackageReference Include="Lyo.Cache" />
paket add Lyo.Cache --version 1.0.6
#r "nuget: Lyo.Cache, 1.0.6"
#:package Lyo.Cache@1.0.6
#addin nuget:?package=Lyo.Cache&version=1.0.6
#tool nuget:?package=Lyo.Cache&version=1.0.6
Lyo.Cache
Local ICacheService plus typed byte payload methods. Serialize values once, store framed bytes (optional compression / encryption on .NET 10+), and round-trip without Fusion's default CLR binary formatter. Fusion-backed ICacheService lives in Lyo.Cache.Fusion.
Features
AddLocalCache/AddLocalCacheFromConfiguration. In-process cache backed byIMemoryCache. WiresICachePayloadCodec,ICachePayloadSerializer, and the payload-awareICacheService(singletonLocalCacheService). The serializer is registered withTryAddSingletonso hosts can pre-register their ownICachePayloadSerializer, for example one bound to the host'sJsonOptions, before callingAddLocalCache*.AddFusionCache(inLyo.Cache.Fusion). Same payload services.FusionCacheServiceimplements the byte and typedGetOrSetPayloadAsync/GetOrSetPayloadAsync<T>overloads.
Benchmarks
- Portfolio suite:
cache
Registration
AddLocalCache/AddLocalCacheFromConfiguration. In-process cache backed byIMemoryCache. WiresICachePayloadCodec,ICachePayloadSerializer, and the payload-awareICacheService(singletonLocalCacheService). The serializer is registered withTryAddSingletonso hosts can pre-register their ownICachePayloadSerializer, for example one bound to the host'sJsonOptions, before callingAddLocalCache*.AddFusionCache(inLyo.Cache.Fusion). Same payload services.FusionCacheServiceimplements the byte and typedGetOrSetPayloadAsync/GetOrSetPayloadAsync<T>overloads.
Expiration
Entries have a duration and an expiration mode. Writes stamp the policy; reads honor it. Existing TimeSpan duration overloads are Absolute. Sliding is opt-in via setupAction (SetSlidingExpiration). Local uses IMemoryCache sliding; Fusion re-Sets on hit. Callers use only ICacheService.
| Mode | Meaning |
|---|---|
Absolute (default) |
Expire Duration after write. Successful reads do not extend lifetime. |
Sliding |
Expire Duration after the last successful access. TryGetValue / GetOrSet / payload hits reset the clock. |
Bypass behavior
When CacheOptions.Enabled is false, LocalCacheService skips storage. Factories run on every call. Set / SetPayload are no-ops. TryGetValue / TryGetPayload return false. Invalidation calls return immediately. Use this for tests, local diagnostics, and dynamic cache-off toggles.
Reflection / metadata TTLs
CacheOptions exposes dedicated lifetimes used by reflection-heavy helpers in other Lyo packages so they can share a single cache instance:
| Option | Default | Purpose |
|---|---|---|
PropertyInfoExpiration |
1 hour | Reflected PropertyInfo lookups, for example query comparison helpers. |
TypeMetadataExpiration |
4 hours | Type metadata used by conversion and comparison. |
PropertyGetterExpiration |
4 hours | Compiled property-getter delegates. |
ComparisonInfoExpiration |
1 hour | Property-difference plan metadata. |
Invalidation methods
ICacheService extends IHealth and exposes these invalidation methods used by Lyo.Api and downstream CRUD plumbing.
| Method | Effect |
|---|---|
InvalidateCacheItem(string key) |
Removes a single entry (key is normalized lower-invariant) and drops its tag index entries. |
InvalidateCacheItemByTag(string tag) |
Removes every entry tagged with tag. |
InvalidateCacheByTypeAsync(string fullTypeName) |
Removes entries tagged for a CLR type name (typical tag shape type:<full name>). |
InvalidateCacheByTypeAsync(Type) / InvalidateCacheByTypeAsync<T>() |
Type-based overloads of the above. |
InvalidateQueryCacheAsync<TDb>() |
Invalidates cached queries tagged for entity type TDb (typically entity:<name>). |
InvalidateAllCachedQueriesAsync() |
Drops all entries tagged for general list/query caching (implementation-defined queries tag). |
MaxBulkQueryInvalidationByIdCount (default 20) controls when CRUD invalidation helpers in Lyo.Api fall back from per-PK tags to a single type-wide
entity:<type> tag during bulk mutations. It is ignored when QueryCacheTagGranularity is Broad (which is always type-wide anyway).
Health
Both ICacheService implementations (LocalCacheService and Fusion's FusionCacheService) implement IHealth with HealthCheckName = "cache". The probe round-trips a short-lived test key tagged lyo-health-check and reports timing through HealthResult.Healthy / HealthResult.Unhealthy. Registering the cache adds this probe to hosts that resolve IEnumerable<IHealth>.
Query cache tag granularity (QueryCacheTagGranularity)
Used by Lyo.Api when tagging POST …/QueryConcrete, POST …/QueryProject, and GET cache entries for Fusion RemoveByTagAsync invalidation.
| Value | Meaning |
|---|---|
Broad (default) |
Type-scoped tags (entity:{typename}, scope/shape tags). Lower CPU when attaching tags on cache write. Any mutation to that entity type clears all cached queries/GETs for the type. |
Granular |
Adds per-primary-key instance tags (entity:{type}:{pk}) so invalidation can target only affected pages. Higher tagging cost, finer busting. |
Set in configuration as "QueryCacheTagGranularity": "Broad" or "Granular". See QueryCacheTagBuilder and QueryCacheInvalidation in Lyo.Api.
Payload pipeline (CacheOptions.Payload)
Used when callers use ICacheService.GetOrSetPayloadAsync / GetOrSetPayloadAsync<T>, for example QueryOptions.CacheQueryResultsAsUtf8Payload in Lyo.Api.
| Area | Role |
|---|---|
ICachePayloadSerializer |
Object to UTF-8 bytes (default: SystemTextJsonCachePayloadSerializer). Hosts can replace the registration so serialization matches HTTP JSON options. |
ICachePayloadCodec |
Frames plaintext bytes. Optional AutoCompress above AutoCompressMinSizeBytes. Optional AutoEncrypt (net10, requires IEncryptionService). See CachePayloadCodec. |
CachePayloadOptions |
AutoCompress, AutoCompressMinSizeBytes, net10 AutoEncrypt / EncryptionKeyId. |
Binding examples: CacheOptions:Payload:AutoCompress, CacheOptions:Payload:AutoCompressMinSizeBytes.
API hosts (Lyo.Api)
AddLyoQueryServices registers ICachePayloadSerializer to use the host's JsonOptions, falling back to shared defaults. Cached query payloads stay aligned with REST JSON for QueryConcreteReq / ProjectionQueryReq shapes. See the Lyo.Api README Query result caching section for QueryOptions:CacheQueryResultsAsUtf8Payload and how POST …/QueryConcrete and POST …/QueryProject both honor it.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Compression(direct, lyo)Lyo.Encryption(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Health(direct, lyo)Lyo.Metrics(direct, lyo)Microsoft.Extensions.Caching.Memory10.0.5(direct, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5(direct, microsoft)Microsoft.Extensions.DependencyInjection10.0.5(direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5(direct, microsoft)System.Text.Json10.0.5(direct, microsoft, netstandard2.0)Lyo.Common(transitive, lyo)Lyo.Hashing(transitive, lyo)Lyo.KeyStore(transitive, lyo)Lyo.Result(transitive, lyo)Lyo.Streams(transitive, lyo)BouncyCastle.Cryptography2.6.2(transitive, third-party, netstandard2.0)EasyCompressor2.1.0(transitive, third-party)Konscious.Security.Cryptography.Argon21.3.1(transitive, third-party)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(transitive, microsoft, net10.0, netstandard2.0)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5(transitive, microsoft)System.Buffers4.6.1(transitive, microsoft, netstandard2.0)System.IO.Hashing10.0.5(transitive, microsoft, net10.0)System.Memory4.6.3(transitive, microsoft, netstandard2.0)System.Threading.Tasks.Extensions4.6.3(transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. 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. net10.0 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Lyo.Compression (>= 1.0.6)
- Lyo.Encryption (>= 1.0.6)
- Lyo.Exceptions (>= 1.0.6)
- Lyo.Health (>= 1.0.6)
- Lyo.Metrics (>= 1.0.6)
- Microsoft.Extensions.Caching.Memory (>= 10.0.5)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- System.Text.Json (>= 10.0.5)
-
net10.0
- Lyo.Compression (>= 1.0.6)
- Lyo.Encryption (>= 1.0.6)
- Lyo.Exceptions (>= 1.0.6)
- Lyo.Health (>= 1.0.6)
- Lyo.Metrics (>= 1.0.6)
- Microsoft.Extensions.Caching.Memory (>= 10.0.5)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Lyo.Cache:
| Package | Downloads |
|---|---|
|
Lyo.Query
Query filtering and property comparison services for IQueryable. Uses Lyo.Query.Models for query types. |
|
|
Lyo.Api
Core API library for building RESTful APIs with Entity Framework Core, caching, and mapping support. |
|
|
Lyo.Discord.Bot
DSharpPlus bot host that syncs Discord guild data to the Lyo API (DI, configuration, extensible base class). |
|
|
Lyo.Cache.Fusion
FusionCache implementation for Lyo.Cache with Redis backplane support for distributed caching. |
|
|
Lyo.Scheduler.Cache
Cache-backed state store for Lyo.Scheduler. Persists scheduler state across restarts using Lyo.Cache. |
GitHub repositories
This package is not used by any popular GitHub repositories.