Coder Social home page Coder Social logo

flashcache's Introduction

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.

flashcache's People

Contributors

ruzzie avatar

Stargazers

Ioan Rîpan avatar  avatar Micro avatar M Platvoet avatar

Watchers

M Platvoet avatar James Cloos avatar Micro avatar

flashcache's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.