EnyimMemcachedCore 3.0.0

Enyim Memcached Client

This is a memcached client library for .NET migrated from EnyimMemcached.

Configure

The appsettings.json Without Authentication

{
  "enyimMemcached": {
    "Servers": [
      {
        "Address": "memcached",
        "Port": 11211
      }
    ],
    "Transcoder": "MessagePackTranscoder"
  }
}

The appsettings.json With Authentication

{
  "enyimMemcached": {
    "Servers": [
      {
        "Address": "memcached",
        "Port": 11211
      }
    ],
    "Authentication": {
      "Type": "Enyim.Caching.Memcached.PlainTextAuthenticator",
      "Parameters": {
        "zone": "",
        "userName": "username",
        "password": "password"
      }
    }
  }
}

Startup.cs

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddEnyimMemcached();
        // services.AddEnyimMemcached("enyimMemcached");
        // services.AddEnyimMemcached(Configuration);
        // services.AddEnyimMemcached(Configuration, "enyimMemcached");
        // services.AddEnyimMemcached(Configuration.GetSection("enyimMemcached"));
        // services.AddEnyimMemcached(options => options.AddServer("memcached", 11211));
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    { 
        app.UseEnyimMemcached();
    }
}

Example usage

Use IMemcachedClient interface

public class HomeController : Controller
{
    private readonly IMemcachedClient _memcachedClient;
    private readonly IBlogPostService _blogPostService;

    public HomeController(IMemcachedClient memcachedClient, IBlogPostService blogPostService)
    {
        _memcachedClient = memcachedClient;
        _blogPostService = blogPostService;
    }

    public async Task<IActionResult> Index()
    {
        var cacheKey = "blogposts-recent";
        var cacheSeconds = 600;

        var posts = await _memcachedClient.GetValueOrCreateAsync(
            cacheKey,
            cacheSeconds,
            async () => await _blogPostService.GetRecent(10));

        return Ok(posts);
    }
}

Use IDistributedCache interface

public class CreativeService
{
    private ICreativeRepository _creativeRepository;
    private IDistributedCache _cache;

    public CreativeService(
        ICreativeRepository creativeRepository,
        IDistributedCache cache)
    {
        _creativeRepository = creativeRepository;
        _cache = cache;
    }

    public async Task<IList<CreativeDTO>> GetCreatives(string unitName)
    {
        var cacheKey = $"creatives_{unitName}";
        IList<CreativeDTO> creatives = null;

        var creativesJson = await _cache.GetStringAsync(cacheKey);
        if (creativesJson == null)
        {
            creatives = await _creativeRepository.GetCreatives(unitName)
                    .ProjectTo<CreativeDTO>().ToListAsync();

            var json = string.Empty;
            if (creatives != null && creatives.Count() > 0)
            {
                json = JsonConvert.SerializeObject(creatives);
            }
            await _cache.SetStringAsync(
                cacheKey, 
                json, 
                new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(5)));
        }
        else
        {
            creatives = JsonConvert.DeserializeObject<List<CreativeDTO>>(creativesJson);
        }

        return creatives;
    }
}

No packages depend on EnyimMemcachedCore.

.NET 6.0

.NET 7.0

.NET 8.0

Version Downloads Last updated
3.4.0 1 6/18/2025
3.3.3-pre2 0 1/24/2025
3.3.3-pre1 0 1/24/2025
3.3.2 1 6/18/2025
3.3.1 1 6/18/2025
3.3.0 1 6/18/2025
3.2.4 1 6/18/2025
3.2.3 1 6/18/2025
3.2.2 1 6/18/2025
3.2.1 1 6/18/2025
3.2.0 1 6/18/2025
3.1.0 1 6/18/2025
3.0.1 1 6/18/2025
3.0.0 1 6/18/2025
2.7.1 1 6/18/2025
2.7.0 1 6/18/2025
2.6.6 1 6/18/2025
2.6.5 1 6/18/2025
2.6.4 1 6/18/2025
2.6.3 1 6/18/2025
2.6.2 3 6/15/2025
2.6.1 1 6/18/2025
2.6.0 1 6/18/2025
2.5.7 1 6/18/2025
2.5.6 2 6/11/2025
2.5.5 1 6/18/2025
2.5.4 1 6/18/2025
2.5.3 1 6/18/2025
2.5.2 1 6/18/2025
2.5.2-preview1 0 12/4/2020
2.5.1 1 6/18/2025
2.5.0 1 6/18/2025
2.5.0-preview3 0 11/30/2020
2.5.0-preview2 0 11/30/2020
2.5.0-preview1 0 11/14/2020
2.4.5 1 6/18/2025
2.4.4 2 6/14/2025
2.4.3 1 6/18/2025
2.4.2 1 6/18/2025
2.4.1 1 6/18/2025
2.4.0 1 6/18/2025
2.3.0 1 6/18/2025
2.2.4 1 6/18/2025
2.2.3 1 6/18/2025
2.2.2 1 6/18/2025
2.2.0 1 6/18/2025
2.1.14 0 5/3/2019
2.1.13 0 4/21/2019
2.1.12 0 12/31/2018
2.1.11 0 12/30/2018
2.1.10 0 9/22/2018
2.1.9 1 6/18/2025
2.1.8 1 6/18/2025
2.1.7 1 6/18/2025
2.1.5 1 6/18/2025
2.1.3 1 6/18/2025
2.1.2 1 6/18/2025
2.1.1 1 6/18/2025
2.1.0.7 0 4/2/2018
2.1.0.6 0 3/26/2018
2.1.0.5 0 3/8/2018
2.1.0.4 0 3/5/2018
2.1.0.3 1 6/13/2025
2.1.0.2 0 1/19/2018
2.1.0.1 0 1/3/2018
2.1.0 1 6/18/2025
2.0.4 1 6/18/2025
2.0.2 1 6/18/2025
2.0.1 1 6/18/2025
2.0.0 1 6/18/2025
2.0.0-beta1 0 7/12/2017
1.1.1.12 0 7/8/2017
1.1.1.11 0 7/8/2017
1.1.1.10 0 5/20/2017
1.1.1.9 0 5/20/2017
1.1.1.8 0 4/20/2017
1.1.1.7 0 3/18/2017
1.1.1.6 0 3/16/2017
1.1.1.5 0 3/7/2017
1.1.1.4 0 3/7/2017
1.1.1.3 0 1/2/2017
1.1.1.2 0 12/24/2016
1.1.1.1 0 12/20/2016
1.1.1 1 6/18/2025
1.1.0.2 0 12/10/2016
1.1.0.1 0 12/8/2016
1.1.0 1 6/18/2025
1.0.0.8 0 11/11/2016
1.0.0.7-preview1 0 10/26/2016
1.0.0.6 0 10/20/2016
1.0.0.5 0 10/19/2016
1.0.0.4 0 10/18/2016
1.0.0.3 0 10/13/2016
1.0.0.2 0 9/27/2016
1.0.0.1 0 9/26/2016
1.0.0 1 6/18/2025