すべてのプロダクト
Search
ドキュメントセンター

:C# .NET EnyimMemcached

最終更新日:Apr 02, 2025

クライアントのダウンロード

ダウンロード アドレス

クライアントについて

クライアント バージョン

C#/.NET サンプルコード

using System.Net;
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
namespace OCS.Memcached
{
    public sealed class MemCached
    {
        private static MemcachedClient MemClient;
        static readonly object padlock = new object();
        // スレッドセーフなシングルトンモード
        public static MemcachedClient getInstance()
        {
            if (MemClient == null)
            {
                lock (padlock)
                {
                    if (MemClient == null)
                    {
                        MemClientInit();                        
                    }
                }
            }
            return MemClient;
        }

        static void MemClientInit()
        {
            // キャッシュを初期化
            MemcachedClientConfiguration memConfig = new MemcachedClientConfiguration();
            IPAddress newaddress = 
   IPAddress.Parse(Dns.GetHostEntry
 ("your_ocs_host").AddressList[0].ToString());// your_ocs_host を ApsaraDB for Memcache イントラネットアドレスに置き換えます
            IPEndPoint ipEndPoint = new IPEndPoint(newaddress, 11211);

              // 設定ファイル - IP
            memConfig.Servers.Add(ipEndPoint);
            // 設定ファイル - プロトコル
           memConfig.Protocol = MemcachedProtocol.Binary;
            // 設定ファイル - 権限
            memConfig.Authentication.Type = typeof(PlainTextAuthenticator);
            memConfig.Authentication.Parameters["zone"] = "";
            memConfig.Authentication.Parameters["userName"] = "username";
            memConfig.Authentication.Parameters["password"] = "password";
      // 次の設定では、インスタンスの最大接続数に従ってください
            memConfig.SocketPool.MinPoolSize = 5;
            memConfig.SocketPool.MaxPoolSize = 200;
            MemClient=new MemcachedClient(memConfig);
                  }
          }
}

依存関係

コード: MemcachedClient MemClient = MemCached.getInstance();