Cache.Tatlisu 1.0.6

There is a newer version of this package available.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cache.Tatlisu" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cache.Tatlisu --version 1.0.6
#r "nuget: Cache.Tatlisu, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.13 627 1/7/2020
1.0.12 496 1/6/2020
1.0.11 525 1/6/2020
1.0.10 535 1/6/2020
1.0.9 537 1/6/2020
1.0.8 555 12/24/2019
1.0.7 464 12/24/2019
1.0.6 534 12/9/2019
1.0.5 462 12/9/2019
1.0.4 499 12/5/2019
1.0.2 475 12/5/2019
1.0.1 480 12/5/2019
1.0.0 504 12/5/2019

Initial 1.0.8 debug mode