{"id":19992820,"url":"https://github.com/evan-rash/FluentCache","last_synced_at":"2025-05-04T12:30:26.468Z","repository":{"id":31500037,"uuid":"35064293","full_name":"evan-rash/FluentCache","owner":"evan-rash","description":"A Fluent library for Caching in C#","archived":false,"fork":false,"pushed_at":"2022-12-07T19:48:37.000Z","size":12767,"stargazers_count":86,"open_issues_count":14,"forks_count":16,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-29T12:19:52.886Z","etag":null,"topics":["c-sharp","caching","dotnet","fluent-library"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evan-rash.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}},"created_at":"2015-05-04T22:43:00.000Z","updated_at":"2024-06-21T22:05:54.000Z","dependencies_parsed_at":"2023-01-14T19:15:47.517Z","dependency_job_id":null,"html_url":"https://github.com/evan-rash/FluentCache","commit_stats":null,"previous_names":["cordialgerm/fluentcache"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evan-rash%2FFluentCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evan-rash%2FFluentCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evan-rash%2FFluentCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evan-rash%2FFluentCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evan-rash","download_url":"https://codeload.github.com/evan-rash/FluentCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252333946,"owners_count":21731301,"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","caching","dotnet","fluent-library"],"created_at":"2024-11-13T04:52:20.219Z","updated_at":"2025-05-04T12:30:25.234Z","avatar_url":"https://github.com/evan-rash.png","language":"C#","readme":"# FluentCache ![](https://raw.githubusercontent.com/cordialgerm/FluentCache/master/FluentCache_24.png)\n\n## A Library for Fluent Caching in C\u0026#35;\n\nFluentCache is a simple, fluent library to help you write clean, legible caching code by reducing boilerplate.\n\n```csharp\ndouble ezResult = cache.Method(r =\u003e r.DoSomeHardParameterizedWork(parameter))\n                       .GetValue();\n```\n\n|Package|Status|\n|---|---|\n|[FluentCache](https://www.nuget.org/packages/FluentCache) |![FluentCache](https://buildstats.info/nuget/FluentCache)|\n|[FluentCache.RuntimeCaching](https://www.nuget.org/packages/FluentCache.RuntimeCaching) |![](https://buildstats.info/nuget/FluentCache.RuntimeCaching)|\n|[FluentCache.Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/FluentCache.Microsoft.Extensions.Caching.Abstractions) |![](https://buildstats.info/nuget/FluentCache.Microsoft.Extensions.Caching.Abstractions)|\n|[FluentCache.Microsoft.Extensions.Caching.Memory](https://www.nuget.org/packages/FluentCache.Microsoft.Extensions.Caching.Memory) |![](https://buildstats.info/nuget/FluentCache.Microsoft.Extensions.Caching.Memory)|\n|[FluentCache.Microsoft.Extensions.Caching.Redis](https://www.nuget.org/packages/FluentCache.Microsoft.Extensions.Caching.Redis) |![](https://buildstats.info/nuget/FluentCache.Microsoft.Extensions.Caching.Redis)|\n\n**Features**:\n\n* **Fluent API**: clean, simple API to encapsulate caching logic\n* **Automatic Cache Key Generation**: refactor at will and never worry about magic strings. FluentCache automatically analyzes the expression tree and generates caching keys based on the type, method, and parameters\n* **Caching policies**: specify caching policies like expiration, validation, and error handling\n* **Cache Implementations**: FluentCache supports common caching implementations and has a simple ICache interface to support other providers\n\nHere's an example of some typical caching code that can be replaced by FluentCache:\n\n```csharp\n//retrieve a value from the cache. If it's not there, load it from the repository \nvar repository = new Repository();\nint parameter = 5;\nstring region = \"FluentCacheExamples\";\nstring cacheKey = \"Samples.DoSomeHardParameterizedWork.\" + parameter;\n\nCachedValue\u003cdouble\u003e cachedValue = cache.Get\u003cdouble\u003e(cacheKey, region);\nif (cachedValue == null)\n{\n    double val = repository.DoSomeHardParameterizedWork(parameter);\n    cachedValue = cache.Set\u003cdouble\u003e(cacheKey, region, val, new CacheExpiration());\n}\ndouble result = cachedValue.Value;\n```\nThere are several issues with this code:\n\n* **boilerplate**: duplicating this code is tedious\n* **magic strings**: the cache key is based on magic strings that won't automatically refactor as methods and parameters change\n* **hard to read**: the intent is overwhelmed by the mechanics\n\n## Examples:\n\n\n### Cache Expiration Policies\n```csharp\ndouble ttlValue = cache.Method(r =\u003e r.DoSomeHardWork())\n                       .ExpireAfter(TimeSpan.FromMinutes(5))\n                       .GetValue();\n```\n\n### Async/Await Retrieval\n```csharp\ndouble asyncValue = await cache.Method(r =\u003e r.DoSomeHardWorkAsync())\n                               .GetValueAsync();\n```\n\n### Validation Strategies\n```csharp\ndouble onlyCachePositiveValues = cache.Method(r =\u003e r.DoSomeHardWork())\n                                      .InvalidateIf(cachedVal =\u003e cachedVal.Value \u003c= 0d)\n                                      .GetValue();\n```\n\n### Clearing Values\n```csharp\ncache.Method(r =\u003e r.DoSomeHardParameterizedWork(parameter))\n     .ClearValue();\n```\n\n\n## Getting Started\n\n### Hello World\n\nTo get started, we will use the `FluentDictionaryCache` to illustrate the various Fluent extension methods provided by the API\n\n```csharp\n//use the simplest cache, which wraps a dictionary\n//other cache implementations are provided in additional nuget packages\nICache myCache = new FluentCache.Simple.FluentDictionaryCache();\n\n//create a wrapper around our Repository\n//wrapper will allow us to cache the results of various Repository methods\nRepository repo = new Repository();\nCache\u003cRepository\u003e myRepositoryCache = myCache.WithSource(repo);\n\n//create and execute a CacheStrategy using Fluent Extension methods\nstring resource = myRepositoryCache.Method(r =\u003e r.RetrieveResource())\n                                   .ExpireAfter(TimeSpan.FromMinutes(30))\n                                   .GetValue();\n```\n\n### Implementations\n\n| Cache Implementation | FluentCache Type | NuGet Package |\n|---|---|---|\n|`ConcurrentDictionary` | `FluentDictionaryCache` | `FluentCache` |\n|`System.Runtime.Caching.MemoryCache`|`FluentMemoryCache`|`FluentCache.RuntimeCaching`|\n|`Microsoft.Extensions.Caching.Memory.MemoryCache`| `FluentMemoryCache` | `FluentCache.Microsoft.Extensions.Caching.Memory`|\n|`Microsoft.Extensions.Caching.Redis.RedisCache` | `FluentRedisCache` | `FluentCache.Microsoft.Extensions.Caching.Redis`|\n|`Microsoft.Extensions.Caching.Memory.IMemoryCache`| `FluentIMemoryCache` | `FluentCache.Microsoft.Extensions.Caching.Abstractions`|\n|`Microsoft.Extensions.Caching.Distributed.IDistributedCache` | `FluentIDistributedCache` | `FluentCache.Microsoft.Extensions.Caching.Abstractions`|\n\nOther caches can implement the `FluentCache.ICache` interface\n\n## New in v4.0.2\n\n1. `.ExpireAfter()` now supports a callback for determining sliding expiration based on cached value\n1. `FluentCache` now only requires .NET Standard 1.1\n1. Assemblies are signed\n\n## New in v4\n\n1. Support for .NET Standard 2.0\n1. New implementations for `Microsoft.Extensions.Caching`\n   1. `Microsoft.Extensions.Caching.Memory.IMemoryCache` added to `FluentCache.Microsoft.Extensions.Caching.Abstractions` nuget package\n   1. `Microsoft.Extensions.Caching.Memory.MemoryCache` added to `FluentCache.Microsoft.Extensions.Caching.Memory` nuget package\n   1. `Microsoft.Extensions.Caching.Distributed.IDistributedCache` added to `FluentCache.Microsoft.Extensions.Caching.Abstractions` nuget package\n   1. `Microsoft.Extensions.Caching.Redis.RedisCache` added to `FluentCache.Microsoft.Extensions.Caching.Redis` nuget package\n1. Support for caching methods on generic repositories\n\nThe previous `FluentCache.Redis` package is deprecated in favor of `FluentCache.Microsoft.Extensions.Caching.Redis`\n\n\n","funding_links":[],"categories":["C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevan-rash%2FFluentCache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevan-rash%2FFluentCache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevan-rash%2FFluentCache/lists"}