Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Ruzzie/flashcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecated use Ruzzie.Common

FlashCache

a fixed size high performant in memory cache

Build status Coverage Status NuGet GitHub license

  • Fixed size, everything is done in memory, so control over maximum size is needed to prevent out of memory errors
  • Multithreaded, multiple readers and writers are accessing the cache
  • Fast as hell
  • Newer added values are expected to be read more frequently
  • Doesn't need to be LIFO, happy with 'good enough'

Example usage

Create a cache

	//creates a cache of approx. 1 mb.
    FlashCache<string, int> flashCache = new FlashCache<string, int>(1);
	
	//When creating a cache for reference types it is advised to pass extra parameters to indicate the estimated size per cache entry. For collection type a default size of 89 will be calculated and for strings a default size of 20
    // (Since the managed enviroment can give accurate sizes of value types)
 	FlashCache<string, string> cache = new FlashCache<string, string>(4,averageSizeInBytesOfKey:48, averageSizeInBytesOfValue:48);

Get or add an item to the cache

	//If the value is present in the cache the cached value will be returned, 
    //else the valueFactory function will be invoked, that value is returned and stored in cache.
	var valueFromCacheOrValueFactory =  cache.GetOrAdd("MyKey", key => 1);

Beware that since fixed sizing of the cache is the primary feature there is no guarantee how long an item will be cached. Since the distribution is based upon the hash, no keys with the same hashcode and different values can be in the cache.

About

a fixed size high performant in-memory cache

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages