Skip to content

Commit

Permalink
docs: add read me
Browse files Browse the repository at this point in the history
  • Loading branch information
MHKarami97 committed Nov 12, 2024
1 parent 17a621a commit fdc76a9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions CacheManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<RepositoryType>public</RepositoryType>
<PackageTags>CacheManager</PackageTags>
<PackageReleaseNotes>CacheManager</PackageReleaseNotes>
<AssemblyVersion>1.0.1</AssemblyVersion>
<FileVersion>1.0.1</FileVersion>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<Version>1.0.2</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MHKarami97.snk</AssemblyOriginatorKeyFile>
<PublicSign>true</PublicSign>
Expand All @@ -26,7 +27,6 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<IncludeContentInPack>true</IncludeContentInPack>
<Version>1.0.1</Version>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
1 change: 0 additions & 1 deletion CacheManagerIntegrationTest/EasyCacheManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class EasyCacheManagerTests : IAsyncLifetime
private SqlConnection _sqlConnection = null!;
private EasyCacheManager<string> _easyCacheManager = null!;


public async Task InitializeAsync()
{
// Set up SQL Server container
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
Manage Cache Easily

### Usage

First install package:

> https://www.nuget.org/packages/EasyMultiCacheManager
then you can use like this:

```csharp
var easyCacheManager = new CacheBuilder<string>()
.AddApi(new ApiConfig
{
Url = StaticData.Api
})
.AddRedis(new RedisConfig
{
ConnectionString = redisConnectionString
})
.AddDb(new DbConfig
{
ConnectionString = sqlConnectionString,
Query = StaticData.QueryToSelect
})
.AddMemory(new MemoryConfig())
.Build(new LockConfig());

var result = await easyCacheManager.GetAsync("My-Key");
```
You can create your own provider with these interfaces:

- IBaseCacheSource
- ICacheSourceWithClear
- ICacheSourceWithSet
- ICacheSourceWithSetAndClear

Default providers are these:

- MemoryCacheSource : ICacheSourceWithSetAndClear : Priority => 1
- RedisCacheSource : ICacheSourceWithSetAndClear : Priority => 2
- DbCacheSource : IBaseCacheSource : Priority => 3
- ApiCacheSource : IBaseCacheSource : Priority => 4

On `IBaseCacheSource` you have only `Get` from cache, for example on `ApiCacheSource` you get real data from api.
if item find from one provider and not exist on other provider, it will automatically set to other providers that implemented from `ICacheSourceWithSetAndClear` or `ICacheSourceWithSet`

### Example
First try get from Memory because it `Priority` is 1, if not exist it try get from redis, after that it try to get from db, and after that it get data from api. if not found it will return null.
also if found on db or api it will set to redis and memory.

### Concurrency
This package use AsyncKeyedLock to handle lock on get, set and clear on specific key. so you use this package on multi thread program.

### Info
You can use all type like class, object, string to cache, for example EasyCacheManager<string>, EasyCacheManager<MyClass>
Priority should be unique, you can't crate EasyCacheManager with list of providers with same Priority

### Clear cache
With `ClearCacheAsync` method you can clear specific key on all providers that implement `ICacheSourceWithClear` or `ICacheSourceWithSetAndClear`

### Set
With `SetAsync` you can manually set value to provides that that implement `ICacheSourceWithSet` or `ICacheSourceWithSetAndClear`

0 comments on commit fdc76a9

Please sign in to comment.