{
  "schema_version": 2,
  "id": "integrate/fusioncache",
  "title": "FusionCache for C#/.NET",
  "url": "https://redis.io/docs/latest/integrate/fusioncache/",
  "summary": "Easy to use, fast and robust hybrid cache with advanced resiliency features for C#/.NET",
  "tags": [
    "docs",
    "integrate",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-03-10T11:44:45-07:00",
  "children": [],
  "page_type": "content",
  "content_hash": "7e1afa62f59a42b5175d639250d693fb7b74cafccebaabc731399ba1ccf50fde",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "FusionCache can transparently handle multiple cache levels by mixing a memory cache and a distributed cache together, getting the best of both worlds. It allows for a sophisticated yet incredibly easy to use developer experience by handling all the complexities of a modern, fast and robust hybrid cache that can deal with the most complex and demanding scenarios. When coupled with Redis, performance, robustness and scaling will not be a problem anymore."
    },
    {
      "id": "key-features",
      "title": "Key Features",
      "role": "content",
      "text": "- **Hybrid**: Can be used as both L1 (memory only) or L1+L2 (memory + distributed)\n- **Tagging**: Powerful tagging capabilities to easily work with multiple entries at once\n- **Backplane**: For instant multi-node distributed notifications\n- **Stampede Protection**: Both on single node (with a memory locker) and multi-node (with a distributed locker)\n- **Redis Perfect Match**: Native support for all distributed parts (cache, backplane and locker)\n- **Resiliency**: Fully resilient thanks to features like Fail-Safe, Eager Refresh, Factory Timeouts, Auto-Recovery and more\n- **Sync+Async**: Full support for both programming models\n- **.NET Ecosystem**: Seamless integration with ASP.NET Core, Entity Framework, and other .NET technologies"
    },
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "Using the dotnet CLI, run:\n\n[code example]\n\nOther packages are also available to work with different distributed caches, serializers, backplanes and more.\nSee the [FusionCache docs](https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/README.md) for more information."
    },
    {
      "id": "getting-started",
      "title": "Getting Started",
      "role": "setup",
      "text": "First, install the packages for Redis (with JSON serialization):\n\n[code example]\n\nThen at startup:\n\n[code example]\n\nUse code like the following to share the Redis connection multiplexer:\n\n[code example]\n\nFusionCache is now ready to use. The simple example below demonstrates the `GetOrSetAsync` method but see [Core Methods](https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/CoreMethods.md) in the FusionCache docs for full details of the API.\n\n[code example]"
    },
    {
      "id": "further-reading",
      "title": "Further Reading",
      "role": "content",
      "text": "To learn more about FusionCache and its advanced features:\n\n- [FusionCache Documentation](https://github.com/ZiggyCreatures/FusionCache)\n- [FusionCache NuGet Package](https://www.nuget.org/packages/ZiggyCreatures.FusionCache)\n- [Redis Backplane Package](https://www.nuget.org/packages/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis)"
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "powershell",
      "code": "dotnet add package ZiggyCreatures.FusionCache",
      "section_id": "install"
    },
    {
      "id": "getting-started-ex0",
      "language": "powershell",
      "code": "dotnet add package ZiggyCreatures.FusionCache\ndotnet add package Microsoft.Extensions.Caching.StackExchangeRedis\ndotnet add package ZiggyCreatures.FusionCache.Serialization.SystemTextJson\ndotnet add package ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis",
      "section_id": "getting-started"
    },
    {
      "id": "getting-started-ex1",
      "language": "csharp",
      "code": "services.AddFusionCache()\n    .WithSerializer(\n        new FusionCacheSystemTextJsonSerializer()\n    )\n    .WithDistributedCache(\n        new RedisCache(new RedisCacheOptions { Configuration = \"localhost:6379\" })\n    )\n    .WithBackplane(\n        new RedisBackplane(new RedisBackplaneOptions { Configuration = \"localhost:6379\" })\n    );",
      "section_id": "getting-started"
    },
    {
      "id": "getting-started-ex2",
      "language": "csharp",
      "code": "var muxer = ConnectionMultiplexer.Connect(\"localhost:6379\")\n\nservices.AddFusionCache()\n    .WithSerializer(\n        new FusionCacheSystemTextJsonSerializer()\n    )\n    .WithDistributedCache(\n        new RedisCache(new RedisCacheOptions { ConnectionMultiplexerFactory = () => muxer })\n    )\n    .WithBackplane(\n        new RedisBackplane(new RedisBackplaneOptions { ConnectionMultiplexerFactory = () => muxer })\n    );",
      "section_id": "getting-started"
    },
    {
      "id": "getting-started-ex3",
      "language": "csharp",
      "code": "var product1 = await cache.GetOrSetAsync<Product>(\n    \"product:1\",\n    async _ => GetProductFromDb(1),\n    tags: [\"sales\", \"product\"]\n);\n\nvar product2 = await cache.GetOrSetAsync<Product>(\n    \"product:2\",\n    async _ => GetProductFromDb(2),\n    tags: [\"sales\", \"product\"]\n);\n\nvar order = await cache.GetOrSetAsync<Order>(\n    \"order:42\",\n    async _ => GetOrderFromDb(42),\n    tags: [\"sales\", \"order\"]\n);\n\n// LATER...\n\nawait cache.RemoveByTagAsync(\"product\");\n\n// NOW BOTH product:1 AND product:2 ARE GONE, ONLY order:42 IS STILL IN THE CACHE",
      "section_id": "getting-started"
    }
  ]
}
