InMemory 1.0.6

A MemoryCache which tries to prevent cache miss for hot entries, by refreshing before expiration.

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 2.8 or higher.

Install-Package InMemory -Version 1.0.6
dotnet add package InMemory --version 1.0.6
<PackageReference Include="InMemory" Version="1.0.6">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add InMemory --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: InMemory, 1.0.6"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install InMemory as a Cake Addin
#addin nuget:?package=InMemory&version=1.0.6

// Install InMemory as a Cake Tool
#tool nuget:?package=InMemory&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

InMemory Cache

Build status
nuget version
Nuget downloads


A MemoryCache which tries to prevent cache miss for hot entries, by refreshing before expiration.

AutoRefreshingCache Example:


// define auto refreshing cache
var cache = new AutoRefreshingCache<string>(expireAfter: 10, refreshAfter: 8, cacheName: "shortTimeCache");

// add key/value data to cache
cache.Inject("key", "value");

// get count of expired cache by key elements
int expiredCacheCount = cache.CountExpiredElements(new[] { "key1", "key2", "key3", "key4" });

// get or update a key in cache, the update operate when occurred that cache was expired, else get old value.
var value = cache.Get("key", () => "new value");

RateLimiter Example:


// define rate limiter for decide can call a method too more or not?
var rateLimiter = new RateLimiter(maxTries: 100, inPeriod: 120, cacheName: "rateLimiterCache");
bool canProc = rateLimiter.CanProceed("method name or a key");

RequestLimiterByIpFilter Example:


// use rate limiter in Web API or MVC Controller to limit request count for all actions by IP filtering
[RequestLimiterByIpFilter] // default: maxTries: 2000, inPeriod: 3600, filterName: nameof(RequestLimiterByIpFilterAttribute)
[RequestLimiterByIpFilter(maxTries: 100, inPeriod: 120, filterName: nameof(TestController))] // customized
public class TestController : Controller
{
	public IActionResult GetTest()
	{
		// ...
	}

	.
	.
	.
}

InMemory Cache

Build status
nuget version
Nuget downloads


A MemoryCache which tries to prevent cache miss for hot entries, by refreshing before expiration.

AutoRefreshingCache Example:


// define auto refreshing cache
var cache = new AutoRefreshingCache<string>(expireAfter: 10, refreshAfter: 8, cacheName: "shortTimeCache");

// add key/value data to cache
cache.Inject("key", "value");

// get count of expired cache by key elements
int expiredCacheCount = cache.CountExpiredElements(new[] { "key1", "key2", "key3", "key4" });

// get or update a key in cache, the update operate when occurred that cache was expired, else get old value.
var value = cache.Get("key", () => "new value");

RateLimiter Example:


// define rate limiter for decide can call a method too more or not?
var rateLimiter = new RateLimiter(maxTries: 100, inPeriod: 120, cacheName: "rateLimiterCache");
bool canProc = rateLimiter.CanProceed("method name or a key");

RequestLimiterByIpFilter Example:


// use rate limiter in Web API or MVC Controller to limit request count for all actions by IP filtering
[RequestLimiterByIpFilter] // default: maxTries: 2000, inPeriod: 3600, filterName: nameof(RequestLimiterByIpFilterAttribute)
[RequestLimiterByIpFilter(maxTries: 100, inPeriod: 120, filterName: nameof(TestController))] // customized
public class TestController : Controller
{
	public IActionResult GetTest()
	{
		// ...
	}

	.
	.
	.
}

Release Notes

* Fix some codes

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.7 7,988 5/9/2018
1.0.6 4,698 5/9/2018
1.0.5 4,219 5/9/2018
1.0.4 4,421 5/5/2018
1.0.3 4,179 5/1/2018
1.0.2 4,222 4/30/2018
1.0.1 4,237 4/30/2018