CacheCrow 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CacheCrow --version 1.0.0
NuGet\Install-Package CacheCrow -Version 1.0.0
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="CacheCrow" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CacheCrow --version 1.0.0
#r "nuget: CacheCrow, 1.0.0"
#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 CacheCrow as a Cake Addin
#addin nuget:?package=CacheCrow&version=1.0.0

// Install CacheCrow as a Cake Tool
#tool nuget:?package=CacheCrow&version=1.0.0

CacheCrow

CacheCrow is a simple key-value, LFU, time-based cache. It is thread safe and lightweight.

Technicality

CacheCrow internally deploys 2 cache storage to maintain data. This helps maintain the performance of the cache. The 2 caches are:

  • Active CacheCrow
  • Dormant CacheCrow
Active CacheCrow

As the name suggests, it is the currently active cache. It uses in-memory to store data entries. It has a limited size that is user defined. At initilization, the entries in dormant cache, having most lookup hits are loaded in active cache. As the time goes, data entries are expired, removed from active cache and new entries having most lookup hits are loaded in-memory from Dormant CacheCrow.

Dormant CacheCrow

Data entries that have least lookup hits resides in dormant cache. All data is stored on disk, in a file '_crow\CacheCrow'. It has no limit on size and can grow upto total disk size. As data entries are in dormant cache, they cannot expire on their own. For removing expired entries 'Cleaner' is employed that is called every x milli-seconds and its value is only configurable at initialization time.

Add Remove data.

Data addition can takes place in 3 conditions:

  • If user is adding new data to CacheCrow, it is first inserted to active cache i.e. if it can accomodate as it has limited size. Else it is inserted into dormant cache.
  • If new space has been accomodated in active cache due to data expiry/removal of data. In this situation, data entry in dormant cache having most lookup hits is loaded into active cache.
  • Auto swapped when key is searched/value is fetched.

Data removal takes place in 3 conditions:

  • If user is removing data from CacheCrow, then corresponding entry is removed from Active or Dormant cache.
  • Data expiry also leads to removal.
  • Auto swapped when key is searched/value is fetched.
Auto data swapping between Active and Dormant CacheCrow

When a data entry in dormant cache is looked up for or its value is fetched then LFU is performed, the data entry with least hits/frequency in active cache is compared with data entry with most hits in dormant cache. If the former has less hits then the two entries are swapped between active and dormant cache. Auto data swapping also works while adding data entries to active cache, however for new entries it works as stated above in section Add Remove data.

Why there are two layers in CacheCrow ?

Internally CacheCrow relies on Dictionary<> and it takes a down hit in performance when the size increases. To maintain its performance 2 different caches have been deployed, one with a fixed size(Active) having frequently used data and the other with a variable size.

Code Snippet

// initialization of singleton class
ICacheCrow<string, string> cache = CacheCrow<string, string>.Initialize(1000);

// adding value to cache
cache.Add("#12","Jack");

// searching value in cache
var flag = cache.LookUp("#12");
if(flag)
{
    Console.WriteLine("Found");
}

// removing value
var value = cache.Remove("#12");

Where can it be used ?

Any small to medium .Net desktop/Web application can make use of CacheCrow for performance boost.

Need more information ?

Please raise an issue or drop me a message at devileatspie@gmail.com

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.1.0 719 12/21/2019
1.0.3 739 1/12/2019
1.0.2.2 664 1/12/2019
1.0.2.1 1,047 4/21/2018
1.0.2 929 3/19/2018
1.0.1 923 3/19/2018
1.0.0 891 2/15/2018

This package includes CacheCrow, a simple LFU based cache that supports data expiry.