ZayniFramework.Caching 2.2.6

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.2.6
dotnet add package ZayniFramework.Caching --version 2.2.6
<PackageReference Include="ZayniFramework.Caching" Version="2.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZayniFramework.Caching --version 2.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ZayniFramework.Caching, 2.2.6"
#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.2.6

// Install ZayniFramework.Caching as a Cake Tool
#tool nuget:?package=ZayniFramework.Caching&version=2.2.6
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 63 3/14/2021
2.30.115 273 3/6/2021
2.30.114 38 3/6/2021
2.20.101 119 3/1/2021
2.19.3 95 2/11/2021
2.19.2 1,622 2/6/2021
2.19.1 150 1/6/2021
2.19.0 157 1/1/2021
2.18.3 156 12/27/2020
2.18.2 885 8/29/2020
2.18.1 119 8/26/2020
2.18.0 4,385 8/20/2020
2.17.135 115 8/19/2020
2.17.134 176 7/28/2020
2.17.133 191 7/27/2020
2.17.132 207 7/18/2020
2.17.131 376 7/11/2020
2.16.130 301 6/13/2020
2.15.128 200 6/3/2020
2.15.127 254 5/31/2020
2.15.126 1,038 4/30/2020
2.14.122 206 4/13/2020
2.13.100 275 3/12/2020
2.12.51 294 2/18/2020
2.11.50 236 2/10/2020
2.10.44 309 1/30/2020
2.9.43 497 1/11/2020
2.8.42 283 1/10/2020
2.8.41 285 1/5/2020
2.7.40 327 1/2/2020
2.7.39 239 1/2/2020
2.7.38 367 1/1/2020
2.6.37 269 12/23/2019
2.6.35 473 12/4/2019
2.6.1 236 12/2/2019
2.6.0 227 11/28/2019
2.5.2 390 11/26/2019
2.5.1 321 11/12/2019
2.5.0 221 11/9/2019
2.4.3 358 10/16/2019
2.4.2 225 10/16/2019
2.4.1 313 9/20/2019
2.3.113 39 3/6/2021
2.3.112 45 3/6/2021
2.3.28 262 9/19/2019
2.3.27 378 8/30/2019
2.3.26 346 8/20/2019
2.3.25 287 8/12/2019
2.3.22 248 7/31/2019
2.3.21 402 7/20/2019
2.3.20 348 6/22/2019
2.3.19 279 6/14/2019
2.3.18 277 6/13/2019
2.3.17 267 6/13/2019
2.3.15 327 6/8/2019
2.3.14 285 6/8/2019
2.3.13 299 5/30/2019
2.3.12 295 5/24/2019
2.3.11 261 5/24/2019
2.3.10 294 5/21/2019
2.3.9 282 5/9/2019
2.3.8 303 5/8/2019
2.3.7 316 4/30/2019
2.3.6 398 4/23/2019
2.3.5 309 4/19/2019
2.3.4 297 4/18/2019
2.3.3 300 4/17/2019
2.3.2 314 4/6/2019
2.3.1 364 12/15/2018
2.3.0 424 12/7/2018
2.2.6 402 11/25/2018
2.2.1 394 11/17/2018
2.2.0 385 11/16/2018
2.1.0 426 11/15/2018
2.0.1 406 11/6/2018
2.0.0 408 11/4/2018
Show less