Support for. NET Core Memcached Client Enyimmemcachedcore

Source: Internet
Author: User

1. Introduction

Enyimmemcachedcore is a Memcached client that supports. NET core, which is migrated from enyimmemcached to. NET core, and the source code is hosted on GitHub: HTTPS://GITHUB.COM/CNB Logs/enyimmemcachedcore, NuGet package address: Https://www.nuget.org/packages/EnyimMemcachedCore.

2. Install the NuGet package using instructions 2.1
Install-package Enyimmemcachedcore
2.2 Configuring 2.2.1 in Appsetting.json

1) Configuration without authentication

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

2) configuration with authentication

{"  enyimmemcached": {    "Servers": [      {        "Address": "memcached",        "Port": 11211      }    ],    " Authentication ": {      " Type ":" Enyim.Caching.Memcached.PlainTextAuthenticator ",      " Parameters ": {        " zone ": "",        "UserName": "UserName",        "password": "Password"      }    }}}  

3) configuration code in the Startup.cs

 Public class startup{    publicvoid  configureservices (iservicecollection services)    {        = = Configuration.getsection ("enyimmemcached"). Bind (options));    }      Public void Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory loggerfactory)    {         app. Useenyimmemcached ();    }}
2.2.2 Direct hard-coded configuration (no configuration file required)

Hard-coded configuration code in Startup.cs

 Public classstartup{ Public voidconfigureservices (iservicecollection services) {services. addenyimmemcached (Options={options. Addserver ("memcached",11211); //options. Addplaintextauthenticator ("", "usename", "password");        }); }             Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env, Iloggerfactory loggerfactory) {app.    Useenyimmemcached (); }}
2.3 Calls

2.3.1 Using the Imemcachedclient interface

 Public classtabnavservice{Privateitabnavrepository _tabnavrepository; Privateimemcachedclient _memcachedclient;  PublicTabnavservice (itabnavrepository tabnavrepository, imemcachedclient memcachedclient) {_tabNa Vrepository=tabnavrepository; _memcachedclient=memcachedclient; }     Public AsyncTask<ienumerable<tabnav>>GetAll () {varCacheKey ="Aboutus_tabnavs_all"; varresult =await _memcachedclient.getasync<IEnumerable<TabNav>>(CacheKey); if(!result. Success) {varTabnavs =await_tabnavrepository.getall (); await _memcachedclient.addasync(CacheKey, Tabnavs, -); returnTabnavs; }        Else        {            returnresult.        Value; }    }}

2.3.2 using Idistributedcache interface (from Microsoft.Extensions.Caching.Abstractions)

 Public classcreativeservice{Privateicreativerepository _creativerepository; PrivateIdistributedcache _cache;  PublicCreativeservice (icreativerepository creativerepository, Idistributedcache cache) {_creative Repository=creativerepository; _cache=Cache; }     Public AsyncTask<ilist<creativedto>> Getcreatives (stringunitname) {        varCacheKey = $"Creatives_{unitname}"; IList<CreativeDTO> creatives =NULL; varCreativesjson =await_cache.        Getstringasync (CacheKey); if(Creativesjson = =NULL) {Creatives=await_creativerepository.getcreatives (unitname). Projectto<CreativeDTO>().            Tolistasync (); varJSON =string.            Empty; if(Creatives! =NULL&& creatives. Count () >0) {JSON=Jsonconvert.serializeobject (creatives); }            await _cache. Setstringasync(CacheKey, JSON,NewDistributedcacheentryoptions (). Setslidingexpiration (Timespan.fromminutes (5))); }        Else{Creatives= jsonconvert.deserializeobject<list<creativedto>>(Creativesjson); }        returncreatives; }}
3. Problem support

If you are having trouble using it, please submit Issue on GitHub.

Support for. NET Core Memcached Client Enyimmemcachedcore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.