CachedQueries 1.0.16

There is a newer version of this package available.
See the version list below for details.
dotnet add package CachedQueries --version 1.0.16                
NuGet\Install-Package CachedQueries -Version 1.0.16                
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="CachedQueries" Version="1.0.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CachedQueries --version 1.0.16                
#r "nuget: CachedQueries, 1.0.16"                
#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 CachedQueries as a Cake Addin
#addin nuget:?package=CachedQueries&version=1.0.16

// Install CachedQueries as a Cake Tool
#tool nuget:?package=CachedQueries&version=1.0.16                

CachedQueries

License NuGet version (CachedQueries) NuGet downloads (CachedQueries) Build status Coverage Status CodeFactor

A library provides IQueryable results caching with smart invalidation.

For example:

    await context.Customers
        .Query(request)
        .ToCachedListAsync(cancellationToken);
        
    await context.Customers
        .FindById(id)
        .CachedFirstOrDefaultAsync(cancellationToken);

Query and FindById extensions could contain filters, include related entities, etc. Using these queries in different places still returns cached results until the Customer entity will be modified.

Setup

Setup with DI

// services is IServicesCollection
services.AddQueriesCaching(options =>
    options.UseEntityFramework());

...
// app is IApplicationBuilder
app.UseQueriesCaching();

Usage

Cache collection

var results = context.Blogs
    .Include(x => x.Posts)
    .ToCachedListAsync(cancellationToken);

// with expiration
var results = context.Posts
    .ToCachedListAsync(Timespan.FromHours(8), cancellationToken);
    
// with custom tags
var results = context.Posts
    .ToCachedListAsync(Timespan.FromHours(8), new List<string> { "all" }, cancellationToken);

Cache item

var result = context.Blogs
    .Include(x => x.Posts)
    .CachedFirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

// with expiration
var result = context.Posts
    .CachedFirstOrDefaultAsync(Timespan.FromHours(8), cancellationToken);
    
// with custom tags
var result = context.Posts
    .CachedFirstOrDefaultAsync(Timespan.FromHours(8), new List<string> { "all" }, cancellationToken);

Invalidate cache

By default, all invalidation tags are retrieved from Include and ThenInclude as navigation properties type names. To invalidate the cache just call this extension before context save changes.

await context.ChangeTracker.ExpireEntitiesCacheAsync();

For more details pls take a look on the tests =)

Product Compatible and additional computed target framework versions.
.NET 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.
  • net7.0

    • No dependencies.

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
2.0.0 1,501 10/18/2024
1.0.18 2,640 7/5/2024
1.0.17 334 2/7/2023
1.0.16 74,368 1/31/2023
1.0.15 655 1/29/2023
1.0.14 1,104 1/25/2023
1.0.13 3,849 1/5/2023
1.0.12 4,381 12/7/2022
1.0.11 6,661 10/21/2022
1.0.10 11,213 7/14/2022
1.0.9 1,977 7/1/2022
1.0.8 425 7/1/2022
1.0.7 430 7/1/2022
1.0.6 12,021 4/11/2022
1.0.5 1,865 3/4/2022
1.0.4 734 2/24/2022
1.0.3 433 2/22/2022
1.0.2 436 2/22/2022
1.0.1 499 2/22/2022
1.0.0 536 2/22/2022