An open API service indexing awesome lists of open source software.

https://github.com/selcukgural/ramcache

RAMCache a simple cache in-memory for .Net applications
https://github.com/selcukgural/ramcache

cache cache-library caching dictionary

Last synced: 2 months ago
JSON representation

RAMCache a simple cache in-memory for .Net applications

Awesome Lists containing this project

README

          

![Logo](https://github.com/selcukgural/RAMCache/blob/master/RAMCache/images/32x.png) RAMCache - a simple cache in-memory for .Net applications
========================================

RAMCache is a [NuGet library](https://www.nuget.org/packages/RAMCache) that you can add in to your .Net or .Net Core project.

`Install-Package RAMCache`

Basics
--------
Add a new entry with will delete when expire time is come. This mean, when entry expire time is come entry will be deleted. For this case expire time is 30 minutes.

```csharp
ramCache.Add(key, value, TimeSpan.FromMinutes(30));
```
or
```csharp
var key = "Barış Manço";
var value = "Nick the chopper";
cache.AddOrUpdate(key,value);
```
Getting value
```csharp
object val;
cache.Get(key, out val); //Nick the chopper
```

Examples
--------
###### Web Api example usage:

``` csharp
services.AddRAMCache(e => e.MaximumItemCount = 5000);
```

```csharp
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();

services.AddRAMCache(e => e.MaximumItemCount = 5000);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
```

Add RAMCache to services and you can use it by injecting

```csharp
private readonly IRAMCache _ramCache;
public WeatherForecastController(IRAMCache ramCache)
{
_ramCache = ramCache;
}
```

###### For other application types example usage:

```csharp
public static readonly RAMCache RamCache = new RAMCache(new RAMCacheServiceOptions{MaximumItemCount = 5000});
```