All Projects → cnblogs → EnyimMemcachedCore

cnblogs / EnyimMemcachedCore

Licence: Apache-2.0 license
A Memcached client for .NET Core. Available on Nuget https://www.nuget.org/packages/EnyimMemcachedCore

Programming Languages

C#
18002 projects
shell
77523 projects

Projects that are alternatives of or similar to EnyimMemcachedCore

Zxw.framework.netcore
基于EF Core的Code First模式的DotNetCore快速开发框架,其中包括DBContext、IOC组件autofac和AspectCore.Injector、代码生成器(也支持DB First)、基于AspectCore的memcache和Redis缓存组件,以及基于ICanPay的支付库和一些日常用的方法和扩展,比如批量插入、更新、删除以及触发器支持,当然还有demo。欢迎提交各种建议、意见和pr~
Stars: ✭ 691 (+383.22%)
Mutual labels:  memcached, dotnetcore
SpotifyApi.NetCore
Lightweight .NET Core wrapper for the Spotify Web API
Stars: ✭ 31 (-78.32%)
Mutual labels:  dotnetcore
swan-aspnetcore
SWAN ASP.NET Core
Stars: ✭ 28 (-80.42%)
Mutual labels:  dotnetcore
WP-Stash
Bridge between WordPress and StashPHP, providing a PSR6-compliant caching system for WordPress
Stars: ✭ 31 (-78.32%)
Mutual labels:  memcached
Huxley2
A cross-platform JSON proxy for the GB railway Live Departure Boards SOAP API
Stars: ✭ 22 (-84.62%)
Mutual labels:  dotnetcore
Discord.Net-Example
Discord.Net Example bots
Stars: ✭ 104 (-27.27%)
Mutual labels:  dotnetcore
memcache
Node.js memcached client with the most efficient ASCII protocol parser
Stars: ✭ 26 (-81.82%)
Mutual labels:  memcached
memcached-php
Memcached client library in plain vanilla PHP.
Stars: ✭ 28 (-80.42%)
Mutual labels:  memcached
AspNetCoreAzureSearch
ASP.NET Core with Azure Cognitive Search
Stars: ✭ 12 (-91.61%)
Mutual labels:  dotnetcore
Waveshare.EPaperDisplay
.Net Core Library to show images on Waveshare E-Paper Displays
Stars: ✭ 17 (-88.11%)
Mutual labels:  dotnetcore
aspnet-core-3-basic-authentication-api
ASP.NET Core 3.1 - Basic HTTP Authentication API
Stars: ✭ 70 (-51.05%)
Mutual labels:  dotnetcore
modular-starter-kit
The starter kit with entire modular approach to help remove boilerplate code in developing
Stars: ✭ 14 (-90.21%)
Mutual labels:  dotnetcore
aspnet-core-3-role-based-authorization-api
ASP.NET Core 3.1 - Role Based Authorization API
Stars: ✭ 110 (-23.08%)
Mutual labels:  dotnetcore
mdserver-web
Simple Linux Panel
Stars: ✭ 1,064 (+644.06%)
Mutual labels:  memcached
NStore
Opinionated eventsourcing library
Stars: ✭ 81 (-43.36%)
Mutual labels:  dotnetcore
django-pymemcache
A Django cache backend built in Pinterest's pymemcache.
Stars: ✭ 40 (-72.03%)
Mutual labels:  memcached
PersianTools.Core
Persian Tools for .Net and .Net Core
Stars: ✭ 25 (-82.52%)
Mutual labels:  dotnetcore
docker-workshop-with-react-aspnetcore-redis-rabbitmq-mssql
An Asp.Net Core Docker workshop project that includes react ui, redis, mssql, rabbitmq and azure pipelines
Stars: ✭ 53 (-62.94%)
Mutual labels:  dotnetcore
google-photos-upload
Upload a local image directory into an Album in Google Photos (works on mac/pc/linux). Coded in C# .NET Core 3.0
Stars: ✭ 26 (-81.82%)
Mutual labels:  dotnetcore
dotnetlive.search
Asp.Net Core + ElasticSearch
Stars: ✭ 18 (-87.41%)
Mutual labels:  dotnetcore

Enyim Memcached Client

This is a .NET Core client library for Memcached migrated from EnyimMemcached. Available on Nuget https://www.nuget.org/packages/EnyimMemcachedCore

Build Status

Configure

The appsettings.json Without Authentication

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

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(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;
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].