All Projects → vieapps → Enyim.Caching

vieapps / Enyim.Caching

Licence: Apache-2.0 license
High performance Memcached client, incorporating both synchronous and asynchronous with various transcoders (Json.NET BSON, MessagePack, Protocol Buffers) on .NET

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Enyim.Caching

Weixinmpsdk
微信全平台 SDK Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 6.0。已支持微信公众号、小程序、小游戏、企业号、企业微信、开放平台、微信支付、JSSDK、微信周边等全平台。 WeChat SDK for C#.
Stars: ✭ 7,098 (+39333.33%)
Mutual labels:  memcached, distributed-cache
Lnmp
LEMP stack/LAMP stack/LNMP stack installation scripts for CentOS/Redhat Debian and Ubuntu
Stars: ✭ 2,488 (+13722.22%)
Mutual labels:  memcached
Wp Spider Cache
Your friendly neighborhood caching solution for WordPress
Stars: ✭ 133 (+638.89%)
Mutual labels:  memcached
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+816.67%)
Mutual labels:  memcached
Sequelize Transparent Cache
Simple to use and universal cache layer for Sequelize
Stars: ✭ 137 (+661.11%)
Mutual labels:  memcached
Ninja Mutex
Mutex implementation for PHP
Stars: ✭ 180 (+900%)
Mutual labels:  memcached
Overlord
Overlord是哔哩哔哩基于Go语言编写的memcache和redis&cluster的代理及集群管理功能,致力于提供自动化高可用的缓存服务解决方案。
Stars: ✭ 1,884 (+10366.67%)
Mutual labels:  memcached
Zapi
基于swoole的异步轻量级api框架,内部封装全套mysql、redis、mongo、memcached异步客户端,可以轻松start、reload、stop,加入数据库的查询模块,框架已经封装好近乎同步写法,底层异步调用。现已支持异步mysql、异步redis、异步http请求.
Stars: ✭ 245 (+1261.11%)
Mutual labels:  memcached
Zend Diagnostics
Universal set of diagnostic tests for PHP applications.
Stars: ✭ 192 (+966.67%)
Mutual labels:  memcached
Cachemanager
CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
Stars: ✭ 2,049 (+11283.33%)
Mutual labels:  memcached
Memjs
A memcache client for node using the binary protocol and SASL authentication
Stars: ✭ 161 (+794.44%)
Mutual labels:  memcached
Memcached Library
A CodeIgniter Library to Interface with the Memcached cache system
Stars: ✭ 139 (+672.22%)
Mutual labels:  memcached
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+11961.11%)
Mutual labels:  memcached
Memcached Operator
A Kubernetes operator for memcached
Stars: ✭ 136 (+655.56%)
Mutual labels:  memcached
Flipper
🐬 Beautiful, performant feature flags for Ruby.
Stars: ✭ 2,732 (+15077.78%)
Mutual labels:  memcached
Zhttp
基于swoole的异步轻量级web框架,内部封装协程异步非阻塞全套mysql、redis、mongo、memcached连接池,可以轻松start、reload、stop,加入数据库的查询模块,框架已经封装好近乎同步写法,底层异步调用
Stars: ✭ 131 (+627.78%)
Mutual labels:  memcached
Oneinstack
OneinStack - A PHP/JAVA Deployment Tool
Stars: ✭ 1,983 (+10916.67%)
Mutual labels:  memcached
Ansible Role Redis
Ansible Role - Redis
Stars: ✭ 176 (+877.78%)
Mutual labels:  memcached
serverless-examples-cached-rds-ws
A serverless framework example project that uses API Gateway, ElastiCache, and RDS PostgreSQL.
Stars: ✭ 45 (+150%)
Mutual labels:  memcached
Caching
⏱ Caching library with easy-to-use API and many cache backends.
Stars: ✭ 234 (+1200%)
Mutual labels:  memcached

VIEApps.Enyim.Caching

The memcached client library on .NET 5 & .NET Standard 2.0:

  • 100% compatible with EnyimMemcached 2.x
  • Fully async (EnyimMemcached still blocks threads while reading from sockets/response)
  • Multiple nodes supported with Ketama for better distribution
  • Object serialization by various transcoders: Json.NET Bson, Protocol Buffers, MessagePack
  • Ready with .NET Core 2.x+/.NET Framework 4.6.1+ with more useful methods (Set, Add, Replace, Refresh, Exists)

NuGet

NuGet

Information

Usage of ASP.NET Core 2.x+ apps

  • Add services.AddMemcached(...) and app.UseMemcached() in Startup.cs
  • Add IMemcachedClient or IDistributedCache into constructor (using dependency injection)

Configure (by the appsettings.json file) without authentication

{
	"Memcached": {
		"Servers": [
		{
			"Address": "192.168.0.2",
			"Port": 11211
		},
		{
			"Address": "192.168.0.3",
			"Port": 11211
		}],
		"SocketPool": {
			"MinPoolSize": 10,
			"MaxPoolSize": 100,
			"DeadTimeout": "00:01:00",
			"ConnectionTimeout": "00:00:05",
			"ReceiveTimeout": "00:00:01"
		}
	}
}

Configure (by the appsettings.json file) with authentication

{
	"Memcached": {
		"Servers": [
		{
			"Address": "192.168.0.2",
			"Port": 11211
		},
		{
			"Address": "192.168.0.3",
			"Port": 11211
		}],
		"SocketPool": {
			"MinPoolSize": 10,
			"MaxPoolSize": 100,
			"DeadTimeout": "00:01:00",
			"ConnectionTimeout": "00:00:05",
			"ReceiveTimeout": "00:00:01"
		},
		"Authentication": {
			"Type": "Enyim.Caching.Memcached.PlainTextAuthenticator, Enyim.Caching",
			"Parameters": {
				"zone": "",
				"userName": "username",
				"password": "password"
			}
		}
	}
}

Startup.cs

public class Startup
{
	public void ConfigureServices(IServiceCollection services)
	{
		// ....
		services.AddMemcached(options => Configuration.GetSection("Memcached").Bind(options));
	}
	
	public void Configure(IApplicationBuilder app, IHostingEnvironment env)
	{ 
		// ....
		app.UseMemcached();
	}
}

Use IMemcachedClient interface

public class TabNavService
{
	ITabNavRepository _tabNavRepository;
	IMemcachedClient _cache;

	public TabNavService(ITabNavRepository tabNavRepository, IMemcachedClient cache)
	{
		_tabNavRepository = tabNavRepository;
		_cache = cache;
	}

	public async Task<IEnumerable<TabNav>> GetAllAsync()
	{
		var cacheKey = "aboutus_tabnavs_all";
		var result = await _cache.GetAsync<IEnumerable<TabNav>>(cacheKey);
		if (result == null)
		{
			var tabNavs = await _tabNavRepository.GetAll();
			await _cache.SetAsync(cacheKey, tabNavs, TimeSpan.FromMinutes(30));
			return tabNavs;
		}
		else
			return result;
	}
}

Use IDistributedCache interface

public class CreativeService
{
	ICreativeRepository _creativeRepository;
	IDistributedCache _cache;

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

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

		var creativesBytes = await _cache.GetAsync(cacheKey);
		var creativesJson = creativesBytes != null ? System.Text.Encoding.UTF8.GetString(creativesBytes) : null;
		if (creativesJson == null)
		{
			creatives = await _creativeRepository.GetCreatives(unitName).ProjectTo<CreativeDTO>().ToListAsync();
			var json = creatives != null && creatives.Count() > 0 ? JsonConvert.SerializeObject(creatives) : string.Empty;
			creativesBytes = System.Text.Encoding.UTF8.GetBytes(json);
			await _cache.SetAsync(cacheKey, creativesBytes, new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(30)));
		}
		else
			creatives = JsonConvert.DeserializeObject<List<CreativeDTO>>(creativesJson);

		return creatives;
	}
}

Usage of .NET Core 2.x+/.NET Framework 4.6.1+ standalone apps

Configure (by the app.config/web.config) without authentication

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientConfigurationSectionHandler, Enyim.Caching" />
	</configSections>
	<memcached>
		<servers>
			<add address="192.168.0.2" port="11211" />
			<add address="192.168.0.3" port="11211" />
		</servers>
		<socketPool minPoolSize="10" maxPoolSize="100" deadTimeout="00:01:00" connectionTimeout="00:00:05" receiveTimeout="00:00:01" />
	</memcached>
</configuration>

Configure (by the app.config/web.config) with authentication

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientConfigurationSectionHandler, Enyim.Caching" />
	</configSections>
	<memcached>
		<servers>
			<add address="192.168.0.2" port="11211" />
			<add address="192.168.0.3" port="11211" />
		</servers>
		<socketPool minPoolSize="10" maxPoolSize="100" deadTimeout="00:01:00" connectionTimeout="00:00:05" receiveTimeout="00:00:01" />
		<authentication type="Enyim.Caching.Memcached.PlainTextAuthenticator, Enyim.Caching" zone="" userName="username" password="password" />
	</memcached>
</configuration>

Example

public class CreativeService
{
	MemcachedClient _cache;

	public CreativeService()
	{
		_cache = new MemcachedClient(ConfigurationManager.GetSection("memcached") as MemcachedClientConfigurationSectionHandler);
	}

	public async Task<IList<CreativeDTO>> GetCreativesAsync(string unitName)
	{
		return await _cache.GetAsync<IList<CreativeDTO>>($"creatives_{unitName}");
	}
}

Other transcoders (Protocol Buffers, Json.NET Bson, MessagePack)

See VIEApps.Enyim.Caching.Transcoders

Need a library for working with other distributed cache (Redis) in the same time?

See VIEApps.Components.Caching

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].