Skip to content

Commit

Permalink
Merge pull request #246 from dotnetcore/dev
Browse files Browse the repository at this point in the history
update docs
  • Loading branch information
catcherwong authored Sep 13, 2020
2 parents 90fc49f + f679343 commit 1f6424f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
91 changes: 91 additions & 0 deletions docs/Disk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# DefaultDiskCachingProvider

Disk is another choice of local caching, the same as LiteDB and SQLite.

EasyCaching.Disk contains most of caching operations that we can use easily.

EasyCaching.Disk is a lib that is based on **EasyCaching.Core**.


# How to use ?

## 1. Install the package via Nuget

```
Install-Package EasyCaching.Disk
```

## 2. Config in Startup class

```csharp
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();

//Important step for SQLite Cache
services.AddEasyCaching(option =>
{
//use disk cache
option.UseDisk(config =>
{
config.DBConfig = new DiskDbOptions { BasePath = Path.GetTempPath() };
});
});
}
}
```

### 3. Call the EasyCachingProvider

The following code show how to use EasyCachingProvider in ASP.NET Core Web API.

```csharp
[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly IEasyCachingProvider _provider;

public ValuesController(IEasyCachingProvider provider)
{
this._provider = provider;
}

[HttpGet]
public string Get()
{
//Remove
_provider.Remove("demo");

//Set
_provider.Set("demo", "123", TimeSpan.FromMinutes(1));

//Get
var res = _provider.Get("demo", () => "456", TimeSpan.FromMinutes(1));

//Get without data retriever
var res = _provider.Get<string>("demo");

//Remove Async
await _provider.RemoveAsync("demo");

//Set Async
await _provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1));

//Get Async
var res = await _provider.GetAsync("demo",async () => await Task.FromResult("456"), TimeSpan.FromMinutes(1));

//Get without data retriever Async
var res = await _provider.GetAsync<string>("demo");

//RemoveByPrefix
_provider.RemoveByPrefix("prefix");

//RemoveByPrefix async
await _provider.RemoveByPrefixAsync("prefix");
}
}
```
2 changes: 1 addition & 1 deletion docs/LiteDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Startup
//Important step for SQLite Cache
services.AddEasyCaching(option =>
{
//use sqlite cache
//use litedb cache
option.UseLiteDB(config =>
{
config.DBConfig = new LiteDBDBOptions { FileName = "s1.ldb" };
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pages:
- Memcached : Memcached.md
- SQLite : SQLite.md
- Hybird : Hybrid.md
- Disk : Disk.md
- LiteDB : LiteDB.md
# - ProviderFactory : ProviderFactory.md
- Provider Factory:
- Overview : FactoryOverview.md
Expand Down

0 comments on commit 1f6424f

Please sign in to comment.