LuminaCache.AspNetCore 1.0.0

dotnet add package LuminaCache.AspNetCore --version 1.0.0                
NuGet\Install-Package LuminaCache.AspNetCore -Version 1.0.0                
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="LuminaCache.AspNetCore" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LuminaCache.AspNetCore --version 1.0.0                
#r "nuget: LuminaCache.AspNetCore, 1.0.0"                
#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.
// Install LuminaCache.AspNetCore as a Cake Addin
#addin nuget:?package=LuminaCache.AspNetCore&version=1.0.0

// Install LuminaCache.AspNetCore as a Cake Tool
#tool nuget:?package=LuminaCache.AspNetCore&version=1.0.0                

Lumina Cache 💡

Lumina Cache is a high-performance, in-memory caching solution tailored for modern .NET applications. Drawing inspiration from the brilliance and speed of light (Lumina is Latin for light), our goal is to ensure that your application's data access is as fast and efficient as photons racing through the void.

🌟 Features

  • Type-safe Property Indexing: Lumina Cache uses lambda expressions, ensuring type-safety and reducing potential runtime errors.
  • Dynamic Cache Refreshing: Keep your cache up-to-date with minimal effort, maximizing data accuracy and relevance.
  • Robust Multi-threading: With built-in safeguards, Lumina Cache is ready for multi-threaded environments, ensuring consistent and reliable performance.
  • Extensible Design: Designed with the future in mind, Lumina Cache is ready to integrate with additional storage mechanisms and strategies.

Setup

Add Lumina Cache to your project

builder.Services.AddLuminaCache();

This will return a LuminaBuilder instance, which can be used to configure the cache.

Add cache object collection
builder.Services.AddLuminaCache()
    .AddCollection<TObject, TPrimaryKey>(x => x.Id, config =>
    {
        config.SetExpiration(TimeSpan.FromHours(1));
        config.AddSecondaryIndex(x => x.SecondaryIndex);
    });
  • AddCollection<TObject, TPrimaryKey>: This is where you define a cache collection for a specific type, TObject. Every object of this type will have its caching behavior managed according to this configuration.

  • Primary Key (x ⇒ x.Id): Every cached item needs a unique identifier, or a primary key. Here, the Id property of the TObject is chosen as that unique identifier.

  • Configuration (inside config):

    • Expiration (SetExpiration(TimeSpan.FromHours(1))): Items in the cache don't stay there forever. Here, we've specified that items should expire after 1 hour. After this time, they're automatically refreshed from the cache using the Backing store.
    • Secondary Index (AddSecondaryIndex(x ⇒ x.SecondaryIndex)): While every item has a primary key, sometimes it's useful to fetch items based on other properties. This method allows you to define additional indices for quicker access. In this case, we're indexing items by a SecondaryIndex property.
Specifying the Backing Store
builder.Services.AddLuminaCache()
    .AddCollection<TObject, TPrimaryKey>(x => x.Id, config =>
    {
        config.SetExpiration(TimeSpan.FromHours(1));
        config.AddSecondaryIndex(x => x.SecondaryIndex);
    }).AddBackingStore<TObjectBackingStore>();

When the cache expires, it needs to be refreshed from the backing store. Here, we've specified that the cache should use the TObjectBackingStore class to refresh the cache.

Add multiple collections and backing stores as needed.
builder.Services.AddLuminaCache()
    .AddCollection<TObject, TPrimaryKey>(x => x.Id, config =>
    {
        config.SetExpiration(TimeSpan.FromHours(1));
        config.AddSecondaryIndex(x => x.SecondaryIndex);
    }).AddBackingStore<TObjectBackingStore>()
    
    .AddCollection<TOtherObject, TPrimaryKey>(x => x.Id, config =>
    {
        config.SetExpiration(TimeSpan.FromHours(1));
        config.AddSecondaryIndex(x => x.SecondaryIndex);
    }).AddBackingStore<TOtherObjectBackingStore>();

Basic Usage

When a collection is added, a client is automatically generated for that collection. This client is a singleton class that can be injected into any class that needs to access the cache.

ICacheClient<TObject, TPrimaryKey>

To use the cache client in your classes (e.g., controllers or services), inject it via the constructor:

private readonly ICacheClient<MyClass, Guid> _cacheClient;

public MyService(ICacheClient<MyClass, Guid> cacheClient)
{
    _cacheClient = cacheClient;
}

Fetching a Single Item

If you know the primary key:

var item = await _cacheClient.GetAsync(myPrimaryKey);
Fetching Multiple Items

Using a list of primary keys:

var items = await _cacheClient.GetManyAsync(myListOfPrimaryKeys);
Fetching by Secondary Index

If you have indexed properties and want to fetch items by them:

var itemsByIndex = await _cacheClient.GetByIndexAsync(x => x.SomeIndexedProperty, someValue);
Executing Custom Queries

Formulate custom LINQ queries on your cached data:

var query = _cacheClient.Query().Where(x => x.SomeProperty == someValue);
var result = await _cacheClient.MaterializeAsync(query);
Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 334 10/24/2023