Lyo.Cache 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Lyo.Cache --version 1.0.1
                    
NuGet\Install-Package Lyo.Cache -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lyo.Cache" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Cache" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.Cache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lyo.Cache --version 1.0.1
                    
#r "nuget: Lyo.Cache, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lyo.Cache@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lyo.Cache&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Cache&version=1.0.1
                    
Install as a Cake Tool

Lyo.Cache

Local and Fusion-backed ICacheService implementations with optional typed byte payload APIs for serializing values once, storing framed bytes (optional compression / encryption on .NET 10+), and round-tripping without Fusion’s default CLR binary formatter for cached objects.

Features

  • AddLocalCache / AddLocalCacheFromConfiguration — in-process cache backed by IMemoryCache; wires ICachePayloadCodec, ICachePayloadSerializer, and the payload-aware ICacheService (singleton LocalCacheService). The serializer is registered with TryAddSingleton so hosts can pre-register their own ICachePayloadSerializer (e.g. one bound to the host's JsonOptions) before calling AddLocalCache*.
  • AddFusionCache (in Lyo.Cache.Fusion) — same payload services; FusionCacheService implements the byte and typed GetOrSetPayloadAsync / * GetOrSetPayloadAsync<T>* overloads.

Benchmarks

  • Portfolio suite: cache

Registration

  • AddLocalCache / AddLocalCacheFromConfiguration — in-process cache backed by IMemoryCache; wires ICachePayloadCodec, ICachePayloadSerializer, and the payload-aware ICacheService (singleton LocalCacheService). The serializer is registered with TryAddSingleton so hosts can pre-register their own ICachePayloadSerializer (e.g. one bound to the host's JsonOptions) before calling AddLocalCache*.
  • AddFusionCache (in Lyo.Cache.Fusion) — same payload services; FusionCacheService implements the byte and typed GetOrSetPayloadAsync / * GetOrSetPayloadAsync<T>* overloads.

Bypass behavior

When CacheOptions.Enabled is false, LocalCacheService skips storage entirely: factories run on every call, Set / SetPayload are no-ops, and TryGetValue / TryGetPayload return false. Invalidation calls return immediately. This is intended 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 (e.g. 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 surface

ICacheService (which extends IHealth) exposes the following invalidation entry points 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 — so registering the cache automatically contributes to host health endpoints 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 ↔ 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, etc.

API hosts (Lyo.Api)

AddLyoQueryServices registers ICachePayloadSerializer to use the host’s JsonOptions (falling back to shared defaults). That keeps cached query payloads 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.Memory 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.DependencyInjection 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 — (direct, microsoft)
  • System.Text.Json 10.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.Cryptography 2.6.2 — (transitive, third-party, netstandard2.0)
  • EasyCompressor 2.1.0 — (transitive, third-party)
  • Konscious.Security.Cryptography.Argon2 1.3.1 — (transitive, third-party)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 — (transitive, microsoft, netstandard2.0)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 — (transitive, microsoft, net10.0, netstandard2.0)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 — (transitive, microsoft)
  • System.Buffers 4.6.1 — (transitive, microsoft, netstandard2.0)
  • System.IO.Hashing 10.0.5 — (transitive, microsoft, net10.0)
  • System.Memory 4.6.3 — (transitive, microsoft, netstandard2.0)
  • System.Threading.Tasks.Extensions 4.6.3 — (transitive, microsoft, netstandard2.0)
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.Cache.Fusion

FusionCache implementation for Lyo.Cache with Redis backplane support for distributed caching.

Lyo.Discord.Bot

DSharpPlus bot host that syncs Discord guild data to the Lyo API (DI, configuration, extensible base class).

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.

Version Downloads Last Updated
1.0.2 0 8/19/2026
1.0.1 38 8/18/2026
1.0.0 120 8/16/2026