Skyb.Framework.Extensions.Caching.MemCached 1.0.5

Skyb.Extensions.Caching.MemCached

Memcached Implementation for IDistributed Cache Memcached library for .NET Core 6, 7, 8

Memcache Integration for IDistributed Cache

Overview

This repository demonstrates how to integrate Memcache as an implementation of the IDistributedCache interface in .NET applications. Memcache is a distributed caching system that is commonly used to improve the performance and scalability of web applications.

Prerequisites

  • .NET Core SDK (version 5.0 or higher)
  • Memcache server (Any)

Installation

  1. Install the Skyb.Extensions.Caching.Memcached package from NuGet:

    dotnet add package Skyb.Extensions.Caching.Memcached
    

Usage

  1. Add Memcache caching to the services collection in your application's Startup.cs file:

    using Skyb.Extensions.Caching.Memcached;
    
    public void ConfigureServices(IServiceCollection services)
    {
        // Add Memcache distributed cache
        var client = services.AddMemCache(TimeSpan.FromSeconds(30), "[ServerUrl]:[ServerPort]"); 
    
        // Other service configurations...
        //Store DateProtection Keys
        services.AddDataProtection().PersistKeysToMemCached(client, "DataProtectionKeys");
    }
    
  2. Now you can inject IDistributedCache into your classes and use it for caching:

    using Microsoft.Extensions.Caching.Distributed;
    
    public class MyService
    {
        private readonly IDistributedCache _cache;
    
        public MyService(IDistributedCache cache)
        {
            _cache = cache;
        }
    
        public async Task<string> GetValueAsync(string key)
        {
            var cachedValue = await _cache.GetStringAsync(key);
    
            if (cachedValue == null)
            {
                // Value not found in cache, retrieve it from the data source
                cachedValue = "Value from data source";
    
                // Cache the value for future requests
                await _cache.SetStringAsync(key, cachedValue, new DistributedCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) // Cache for 10 minutes
                });
            }
    
            return cachedValue;
        }
    }
    

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues if you encounter any problems.

License

This project is licensed under the MIT License - see the LICENSE file for details.

💰 You can help me by Donating

BuyMeACoffee

Showing the top 20 packages that depend on Skyb.Framework.Extensions.Caching.MemCached.

Packages Downloads
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
0
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
1
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
3
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
4
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
5
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
6
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
12
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
13
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
15
Skyb.Nebula.Shared
SSC Nebula shared infrastructure — SSCStartup, SSCContext, shared persistence models, middleware, and services
47

Version Downloads Last updated
1.0.9 0 08/29/2026
1.0.8 19 08/28/2026
1.0.7 47 08/01/2026
1.0.6 5 07/29/2026
1.0.5 8 07/29/2026
1.0.4 24 07/22/2026
1.0.3 1 07/22/2026
1.0.2 3 07/09/2026
1.0.1 1 07/09/2026
1.0.0 1 07/08/2026