ZayniFramework.Caching 2.1.0

This is a cache management for .NET application. You can store you data in in-process memory, Redis server, MySQL memory table engine or Zayni Framework's build-in Remote.ShareData.Service.

There is a newer version of this package available.
See the version list below for details.
Install-Package ZayniFramework.Caching -Version 2.1.0
dotnet add package ZayniFramework.Caching --version 2.1.0
<PackageReference Include="ZayniFramework.Caching" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZayniFramework.Caching --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ZayniFramework.Caching, 2.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ZayniFramework.Caching as a Cake Addin
#addin nuget:?package=ZayniFramework.Caching&version=2.1.0

// Install ZayniFramework.Caching as a Cake Tool
#tool nuget:?package=ZayniFramework.Caching&version=2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CacheManager example.

Add namespace using.

using ZayniFramework.Caching;
using ZayniFramework.Common;

Add CachingSettings config section in your app.config or web.config file.

<!--managerMode support: Memory, Redis, MySQLMemory, RemoteCache-->
<CachingSettings managerMode="Redis">
    <CachePool resetEnable="true" cleanerIntervalSecond="3" maxCapacity="10000" refreshIntervalMinute="1" />
    <CacheData timeoutInterval="0" />
    <RedisCache>
        <add name="XXXRedisService" isDefault="true" dbActionLog="true" host="XXX.XXX.XXX.XXX" port="6379" account="" password="" dbNumber="10" connectTimeout="1000" responseTimeout="3500" />
        <!--<add name="BBBRedisService" isDefault="true" dbActionLog="true" host="XXX.XXX.XXX.XXX" port="6379" account="" password="" dbNumber="10" connectTimeout="1000" responseTimeout="3500" />-->
    </RedisCache>
    <RemoteCache defaultCacheClientName="RemoteCacheTest1"></RemoteCache>
    <!--<MySQLMemoryCache defaultConnectionName="ZayniCache"></MySQLMemoryCache>-->
</CachingSettings>

Put data into CacheManager. Use CacheManager.Put() static method.

public void PutDataTest()
{
    string key = "somekey";

    var model = new
    {
        Name   = "Amber",
        Age    = 23,
        Sex    = "F",
        Emails = new List<string>()
        {
            "amber@gmail.com",
            "amber@hotmail.com"
        },
        Profile = new
        {
            Token   = Guid.NewGuid().ToString(),
            DoB     = new DateTime( 1998, 2, 14 ),
            Comment = "Hello, this is Amber."
        }
    };

    var cacheProp = new CacheProperty()
    {
        CacheId         = key,
        Data            = model,
        RefreshCallback = () => new
        {
            Name   = "Belle Claire",
            Age    = 23,
            Sex    = "F",
            Emails = new List<string>()
            {
                "belle.claire@gmail.com",
                "belle.claire@hotmail.com"
            },
            Profile = new
            {
                Token   = Guid.NewGuid().ToString(),
                DoB     = new DateTime( 1998, 2, 14 ),
                Comment = "Hi"
            }
        }
    };

    bool success = CacheManager.Put( cacheProp );
    Assert.IsTrue( success );
}

Put data into CacheManager in a HashProperty data structure.<br/>
Get HashProperty data from CacheManager.

var hashs = new HashProperty[] 
{
    new HashProperty( "a1", "Hello Fiona!" ),
    new HashProperty( "a2", true ),
    new HashProperty( "a3", new DateTime( 2018, 2, 7 ) ),
    new HashProperty( "a4", 45.26 ),
    new HashProperty( "a5", 500 ),
    new HashProperty( "a6", 3333.77M ),
};

bool success = CacheManager.PutHashProperty( "aaa", hashs );

var a1 = CacheManager.GetHashProperty( "aaa", "a1" );
Assert.AreEqual( "Hello Fiona", a1.Data + "" );

var a2 = CacheManager.GetHashProperty( "aaa", "a2" );
Assert.AreEqual( true, Convert.ToBoolean( a2.Data + "" ) );

var a3 = CacheManager.GetHashProperty( "aaa", "a3" );
Assert.AreEqual( new DateTime( 2018, 2, 7 ), Convert.ToDateTime( a3.Data ) );

// Get all hash properties with the main cacheId.
var gp = CacheManager.GetHashProperties( "aaa" );

Put and Get data with CacheManager.

var model = new UserTestModel()
{
    Name = "Amber",
    Age  = 23,
    Sex  = "F"
};

bool success = CacheManager.Put( new CacheProperty() { CacheId = "test02", Data = model } );
var r = CacheManager.Get<UserTestModel>( "test02" );

Clear all the data in CacheManager. User CacheManager.Clear() static method.

CacheManager.Clear();

More detail sample code. You can go to Test/UnitTests/Zayni.Caching.Test directory.

CacheManager example.

Add namespace using.

using ZayniFramework.Caching;
using ZayniFramework.Common;

Add CachingSettings config section in your app.config or web.config file.

<!--managerMode support: Memory, Redis, MySQLMemory, RemoteCache-->
<CachingSettings managerMode="Redis">
    <CachePool resetEnable="true" cleanerIntervalSecond="3" maxCapacity="10000" refreshIntervalMinute="1" />
    <CacheData timeoutInterval="0" />
    <RedisCache>
        <add name="XXXRedisService" isDefault="true" dbActionLog="true" host="XXX.XXX.XXX.XXX" port="6379" account="" password="" dbNumber="10" connectTimeout="1000" responseTimeout="3500" />
        <!--<add name="BBBRedisService" isDefault="true" dbActionLog="true" host="XXX.XXX.XXX.XXX" port="6379" account="" password="" dbNumber="10" connectTimeout="1000" responseTimeout="3500" />-->
    </RedisCache>
    <RemoteCache defaultCacheClientName="RemoteCacheTest1"></RemoteCache>
    <!--<MySQLMemoryCache defaultConnectionName="ZayniCache"></MySQLMemoryCache>-->
</CachingSettings>

Put data into CacheManager. Use CacheManager.Put() static method.

public void PutDataTest()
{
    string key = "somekey";

    var model = new
    {
        Name   = "Amber",
        Age    = 23,
        Sex    = "F",
        Emails = new List<string>()
        {
            "amber@gmail.com",
            "amber@hotmail.com"
        },
        Profile = new
        {
            Token   = Guid.NewGuid().ToString(),
            DoB     = new DateTime( 1998, 2, 14 ),
            Comment = "Hello, this is Amber."
        }
    };

    var cacheProp = new CacheProperty()
    {
        CacheId         = key,
        Data            = model,
        RefreshCallback = () => new
        {
            Name   = "Belle Claire",
            Age    = 23,
            Sex    = "F",
            Emails = new List<string>()
            {
                "belle.claire@gmail.com",
                "belle.claire@hotmail.com"
            },
            Profile = new
            {
                Token   = Guid.NewGuid().ToString(),
                DoB     = new DateTime( 1998, 2, 14 ),
                Comment = "Hi"
            }
        }
    };

    bool success = CacheManager.Put( cacheProp );
    Assert.IsTrue( success );
}

Put data into CacheManager in a HashProperty data structure.<br/>
Get HashProperty data from CacheManager.

var hashs = new HashProperty[] 
{
    new HashProperty( "a1", "Hello Fiona!" ),
    new HashProperty( "a2", true ),
    new HashProperty( "a3", new DateTime( 2018, 2, 7 ) ),
    new HashProperty( "a4", 45.26 ),
    new HashProperty( "a5", 500 ),
    new HashProperty( "a6", 3333.77M ),
};

bool success = CacheManager.PutHashProperty( "aaa", hashs );

var a1 = CacheManager.GetHashProperty( "aaa", "a1" );
Assert.AreEqual( "Hello Fiona", a1.Data + "" );

var a2 = CacheManager.GetHashProperty( "aaa", "a2" );
Assert.AreEqual( true, Convert.ToBoolean( a2.Data + "" ) );

var a3 = CacheManager.GetHashProperty( "aaa", "a3" );
Assert.AreEqual( new DateTime( 2018, 2, 7 ), Convert.ToDateTime( a3.Data ) );

// Get all hash properties with the main cacheId.
var gp = CacheManager.GetHashProperties( "aaa" );

Put and Get data with CacheManager.

var model = new UserTestModel()
{
    Name = "Amber",
    Age  = 23,
    Sex  = "F"
};

bool success = CacheManager.Put( new CacheProperty() { CacheId = "test02", Data = model } );
var r = CacheManager.Get<UserTestModel>( "test02" );

Clear all the data in CacheManager. User CacheManager.Clear() static method.

CacheManager.Clear();

More detail sample code. You can go to Test/UnitTests/Zayni.Caching.Test directory.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ZayniFramework.Caching:

Package Downloads
ZayniFramework.DataAccess.LightORM
This is a lightweight CRUD ORM template for .NET data access application. You can use the DataContext to execute Insert, Update, Delete and Select action to database.
ZayniFramework.Caching.RemoteCache
This is a ZayniFramework build-in Remote Share Data Service. You can use the ZayniFramework.Caching module to store data into this service. Also it support telnent service commands.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.31.120 64 3/14/2021
2.30.115 328 3/6/2021
2.30.114 39 3/6/2021
2.20.101 129 3/1/2021
2.19.3 96 2/11/2021
2.19.2 1,841 2/6/2021
2.19.1 151 1/6/2021
2.19.0 158 1/1/2021
2.18.3 157 12/27/2020
2.18.2 886 8/29/2020
2.18.1 120 8/26/2020
2.18.0 4,386 8/20/2020
2.17.135 121 8/19/2020
2.17.134 177 7/28/2020
2.17.133 192 7/27/2020
2.17.132 208 7/18/2020
2.17.131 377 7/11/2020
2.16.130 302 6/13/2020
2.15.128 201 6/3/2020
2.15.127 255 5/31/2020
2.15.126 1,039 4/30/2020
2.14.122 207 4/13/2020
2.13.100 276 3/12/2020
2.12.51 295 2/18/2020
2.11.50 237 2/10/2020
2.10.44 310 1/30/2020
2.9.43 503 1/11/2020
2.8.42 289 1/10/2020
2.8.41 286 1/5/2020
2.7.40 328 1/2/2020
2.7.39 240 1/2/2020
2.7.38 368 1/1/2020
2.6.37 270 12/23/2019
2.6.35 474 12/4/2019
2.6.1 237 12/2/2019
2.6.0 228 11/28/2019
2.5.2 391 11/26/2019
2.5.1 322 11/12/2019
2.5.0 222 11/9/2019
2.4.3 364 10/16/2019
2.4.2 226 10/16/2019
2.4.1 314 9/20/2019
2.3.113 40 3/6/2021
2.3.112 46 3/6/2021
2.3.28 263 9/19/2019
2.3.27 379 8/30/2019
2.3.26 347 8/20/2019
2.3.25 288 8/12/2019
2.3.22 249 7/31/2019
2.3.21 408 7/20/2019
2.3.20 349 6/22/2019
2.3.19 280 6/14/2019
2.3.18 278 6/13/2019
2.3.17 268 6/13/2019
2.3.15 328 6/8/2019
2.3.14 286 6/8/2019
2.3.13 300 5/30/2019
2.3.12 296 5/24/2019
2.3.11 262 5/24/2019
2.3.10 295 5/21/2019
2.3.9 283 5/9/2019
2.3.8 304 5/8/2019
2.3.7 317 4/30/2019
2.3.6 399 4/23/2019
2.3.5 310 4/19/2019
2.3.4 298 4/18/2019
2.3.3 301 4/17/2019
2.3.2 315 4/6/2019
2.3.1 365 12/15/2018
2.3.0 425 12/7/2018
2.2.6 403 11/25/2018
2.2.1 395 11/17/2018
2.2.0 386 11/16/2018
2.1.0 427 11/15/2018
2.0.1 407 11/6/2018
2.0.0 409 11/4/2018
Show less