Cache.Tatlisu
1.0.6
See the version list below for details.
dotnet add package Cache.Tatlisu --version 1.0.6
NuGet\Install-Package Cache.Tatlisu -Version 1.0.6
<PackageReference Include="Cache.Tatlisu" Version="1.0.6" />
paket add Cache.Tatlisu --version 1.0.6
#r "nuget: Cache.Tatlisu, 1.0.6"
// Install Cache.Tatlisu as a Cake Addin
#addin nuget:?package=Cache.Tatlisu&version=1.0.6
// Install Cache.Tatlisu as a Cake Tool
#tool nuget:?package=Cache.Tatlisu&version=1.0.6
Cache.Tatlisu
How to use this cache?
First, you should add dependency injection at startup :
public virtual void ConfigureServices(IServiceCollection services)
{
var dbConnectionString = Configuration.GetConnectionString("DatabaseConnectionString");
var redisConnectionString = Configuration.GetConnectionString("RedisConnectionString");
services.AddTatlisuCache<YOUR_DATABASE_CONTEXT>(dbConnectionString, redisConnectionString);
}
If you call this 'services.AddTatlisuCache' extension. You don't need to add YOUR_DATABASE_CONTEXT to dependency injection.
Create your your repository class with cache :
public class CatalogRepositoryCacheManager : RepositoryDataManager<YOUR_DATABASE_CONTEXT>
{
public CatalogRepositoryManager(LocalCacheProvider memoryProvider, RedisProvider redisProvider, YOUR_DATABASE_CONTEXT dbContext) : base(memoryProvider, redisProvider, dbContext)
{
}
public async Task<Catalog> GetDeliveryClubCatalog(Func<Task<Catalog>> func, string restaurantId)
{
var cacheKey = string.Format(CacheKey.CATALOG_KEY, restaurantId);
var cacheData = await _LocalCacheProvider.Get(cacheKey, TimeSpan.FromMinutes(5),
async (x, y) => await _RedisProvider.Get(cacheKey, TimeSpan.FromMinutes(60),
async (it1, it2) => await func.Invoke()));
return cacheData;
}
}
In this example. Has data in memory cache ? If yes return data from memoryCache. No then has data in redis cache ? If yes return data from Redis No then get data from Func by invoke
After that write data to Redis with expire time. After that write data to Memory with expire time. Return data to caller.
You can change the order between Redis and MemoryCache You can get data from anywhere just not YOUR_DATABASE_CONTEXT;
You can get this CatalogRepositoryCacheManager class from constructor :
public class CatalogService
{
private readonly CatalogRepositoryManager _catalogRepositoryCacheManager;
public CatalogService(CatalogRepositoryManager catalogRepositoryManager)
{
_catalogRepositoryManager = catalogRepositoryManager;
}
}
You can use however you want :
Memory → Redis → Data
Redis → Memory → Data
Memory → Data
Redis → Data
Only Data
Settings :
There is static class that you can change via cachesettings.
TatlisuCacheSettings.DeveloperMode = false;
Default value is true;
If Developer mode is true,
If Redis get error then throw exceptions.
Else Developer mode is false
If Redis get error then can't throw exception and code will go on executing without RedisCache
We are using protobuf serialization that's why you have to use [ProtoMember(X)] attribute at your class properties otherwise you can't store data in Redis.
Example :
[ProtoContract]
public class Catalog
{
#region Field
#endregion
#region Property
[JsonProperty("lastUpdatedAt")]
[ProtoMember(1)]
public DateTime LastUpdatedAt { get; set; }
[JsonProperty("menuItems")]
[ProtoMember(2)]
public MenuItem MenuItems { get; set; }
#endregion
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
- Microsoft.EntityFrameworkCore (>= 3.1.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 3.1.0)
- Microsoft.Extensions.Caching.Memory (>= 3.1.0)
- Newtonsoft.Json (>= 12.0.3)
- protobuf-net (>= 2.4.4)
- StackExchange.Redis (>= 2.0.601)
- System.Data.SqlClient (>= 4.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial 1.0.8 debug mode