{"id":19100070,"url":"https://github.com/SteffenMangold/EntityFrameworkCore.Cacheable","last_synced_at":"2025-04-18T17:32:39.629Z","repository":{"id":40830973,"uuid":"162924424","full_name":"SteffenMangold/EntityFrameworkCore.Cacheable","owner":"SteffenMangold","description":"EntityFrameworkCore second level cache","archived":false,"fork":false,"pushed_at":"2024-01-31T16:41:42.000Z","size":253,"stargazers_count":193,"open_issues_count":13,"forks_count":27,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-04T15:06:40.757Z","etag":null,"topics":["c-sharp","cache","database","dotnet-core","dotnet-framework","dotnet-standard","entity-framework","orm"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SteffenMangold.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-23T21:16:47.000Z","updated_at":"2024-09-26T03:57:32.000Z","dependencies_parsed_at":"2024-06-18T18:43:45.024Z","dependency_job_id":"aa411c4b-d15f-4a16-9eb6-1cc3e43b757b","html_url":"https://github.com/SteffenMangold/EntityFrameworkCore.Cacheable","commit_stats":{"total_commits":46,"total_committers":1,"mean_commits":46.0,"dds":0.0,"last_synced_commit":"41abeaa4bddf7811e6b39ecd58ff2bfeaf8c8b32"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteffenMangold%2FEntityFrameworkCore.Cacheable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteffenMangold%2FEntityFrameworkCore.Cacheable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteffenMangold%2FEntityFrameworkCore.Cacheable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteffenMangold%2FEntityFrameworkCore.Cacheable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SteffenMangold","download_url":"https://codeload.github.com/SteffenMangold/EntityFrameworkCore.Cacheable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783091,"owners_count":17201903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","cache","database","dotnet-core","dotnet-framework","dotnet-standard","entity-framework","orm"],"created_at":"2024-11-09T03:52:28.495Z","updated_at":"2025-04-18T17:32:39.620Z","avatar_url":"https://github.com/SteffenMangold.png","language":"C#","readme":"﻿\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/SteffenMangold/EntityFrameworkCore.Cacheable/master/nuget_icon_light.png?size=72\" width=\"96\"/\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003e\n  EntityFrameworkCore.Cacheable\n\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  A high-performance second-level query cache for \u003ca href=\"https://github.com/aspnet/EntityFrameworkCore\"\u003eEntity Framework Core\u003c/a\u003e.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://ci.appveyor.com/project/SteffenMangold/entityframeworkcore-cacheable\"\u003e\u003cimg src=\"https://ci.appveyor.com/api/projects/status/8h2kg4gjcv85w6wg?svg=true\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codeclimate.com/github/SteffenMangold/EntityFrameworkCore.Cacheable/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/541ce9c419c532bcd292/maintainability\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://lgtm.com/projects/g/SteffenMangold/EntityFrameworkCore.Cacheable/alerts/\"\u003e\u003cimg src=\"https://img.shields.io/lgtm/alerts/g/SteffenMangold/EntityFrameworkCore.Cacheable.svg?logo=lgtm\u0026logoWidth=18\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.nuget.org/packages/EntityFrameworkCore.Cacheable/\"\u003e\u003cimg src=\"https://buildstats.info/nuget/EntityFrameworkCore.Cacheable\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## What is EF Core Cacheable?\n\nEntity Framework (EF) Core Cacheable is an extension library for the popular Entity Framework data access technology.\n\nIt provides caching functionality for all types of query results. Based on the expression tree and parameters, the context decides whether to execute the query against the database or return the result from memory.\n\n## How caching affects performance\n\n\nThis is a sample result of 1,000 iterations of an uncached and cached query called against a well-performing MSSQL database.\n\n```\nAverage database query duration [+00:00:00.1698972].\nAverage cache query duration [+00:00:00.0000650].\nCached queries are x2,611 times faster.\n```\n\nEven with an InMemory test database, the results are significantly faster.\n\n```\nAverage database query duration [+00:00:00.0026076].\nAverage cache query duration [+00:00:00.0000411].\nCached queries are x63 times faster.\n```\n\nThe performance gain can be even higher, depending on the database performance.\n\n\n## Install via NuGet\n\nYou can view the [package page on NuGet](https://www.nuget.org/packages/EntityFrameworkCore.Cacheable/).\n\nTo install `EntityFrameworkCore.Cacheable`, run the following command in the Package Manager Console:\n\n```\nPM\u003e Install-Package EntityFrameworkCore.Cacheable\n```\n\n\nThis library also uses the [Data.HashFunction](https://github.com/brandondahler/Data.HashFunction/) and [aspnet.Extensions](https://github.com/aspnet/Extensions) as InMemory cache.\n\n\n## Configuring a DbContext\n\nThere are three types of configurations for the DbContext to support `Cachable.`\nEach sample only uses' UseSqlite' to show the pattern.\n\nFor more information about this, please read [configuring DbContextOptions](https://docs.microsoft.com/de-de/ef/core/miscellaneous/configuring-dbcontext#configuring-dbcontextoptions).\n\n### Constructor argument\n\nApplication code to initialize from constructor argument:\n\n```csharp\nvar optionsBuilder = new DbContextOptionsBuilder\u003cCacheableBloggingContext\u003e();\noptionsBuilder\n    .UseSqlite(\"Data Source=blog.db\")\n    .UseSecondLevelCache();\n\nusing (var context = new CacheableBloggingContext(optionsBuilder.Options))\n{\n    // do stuff\n}\n```\n\n### OnConfiguring\n\nContext code with `OnConfiguring`:\n\n```csharp\npublic partial class CacheableBloggingContext : DbContext\n{\n    public DbSet\u003cBlog\u003e Blogs { get; set; }\n\n    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\n    {\n        if (!optionsBuilder.IsConfigured)\n        {\n            optionsBuilder.UseSqlite(\"Data Source=blog.db\");\n            optionsBuilder.UseSecondLevelCache();\n        }\n    }\n}\n```\n\n### Using DbContext with dependency injection\n\nAdding the Dbcontext to dependency injection:\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddDbContext\u003cCacheableBloggingContext\u003e(options =\u003e options\n        .UseSqlite(\"Data Source=blog.db\"))\n        .UseSecondLevelCache();\n}\n```\n\n\nThis requires [adding a constructor argument](https://docs.microsoft.com/de-de/ef/core/miscellaneous/configuring-dbcontext#using-dbcontext-with-dependency-injection) to your DbContext type that accepts DbContextOptions\u003cTContext\u003e.\n\n\n## Usage\n\nTo use result caching, you simply need to add `.Cacheable(...` to your query and define a TTL parameter.\n\n\n```csharp\nvar cacheableQuery = cacheableContext.Books\n\t.Include(d =\u003e d.Pages)\n\t.ThenInclude(d =\u003e d.Lines)\n\t.Where(d =\u003e d.ID == 200)\n\t.Cacheable(TimeSpan.FromSeconds(60));\n```\n\n### Custom Cache Provider\n\n\nAlternatively, you can provide a custom implementation of `ICacheProvider` (default is `MemoryCacheProvider`).\nThis provides an easy option for supporting other caching systems like [![](https://redis.io/images/favicon.png) redis](https://redis.io/) or [Memcached](https://memcached.org/).\n\n```csharp\noptionsBuilder.UseSecondLevelCache(new MyCachingProvider());\n```\n\n\n-----------------\n\n\n## Contributors\n\nThe following contributors have either created (that only me:stuck_out_tongue_winking_eye:) the project, have contributed\ncode, are actively maintaining it (including documentation), or in other ways\nbeing helpful contributors to this project. \n\n\n|                                                                                    | Name                  | GitHub                                                  |\n| :--------------------------------------------------------------------------------: | --------------------- | ------------------------------------------------------- |\n| \u003cimg src=\"https://avatars.githubusercontent.com/u/20702171?size=72\" width=\"72\"/\u003e   | Steffen Mangold       | [@SteffenMangold](https://github.com/SteffenMangold)    |\n| \u003cimg src=\"https://avatars.githubusercontent.com/u/1528107?size=72\" width=\"72\"/\u003e    | Smit Patel            | [@smitpatel](https://github.com/smitpatel)              |\n","funding_links":[],"categories":["database","C\\#","C# #"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSteffenMangold%2FEntityFrameworkCore.Cacheable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSteffenMangold%2FEntityFrameworkCore.Cacheable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSteffenMangold%2FEntityFrameworkCore.Cacheable/lists"}