Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

romansource/WeakenedCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

WeakenedCache

Acts like a regular cache but with the ability to make its entries weakly referenced

Create cache

var cache = new WeakenedCache();

Fill it

var instance1 = new SampleRefType(1);
var instance2 = new SampleRefType(2);
var instance3 = new SampleRefType(3);

cache.Put(Key1, instance1, WeakenedCache.Priority.Low);
cache.Put(Key2, instance2, WeakenedCache.Priority.Normal);
cache.Put(Key3, instance3, WeakenedCache.Priority.High);

Get values

(cache.Take(Key1) as SampleRefType).Value; // 1

or use generic

cache.Take<SampleRefType>(Key2)?.Value; // 2
cache.Take<SampleRefType>(Key3)?.Value; // 3

Weaken items of some priorities

cache.WeakenUpTo(WeakenedCache.Priority.Normal);

Put items with expiration of Weaken type

var someInstance = new SampleRefType();

cache.Put(
key: Key4,
value: someInstance,
priority: WeakenedCache.Priority.Normal,
expiration: TimeSpan.FromSeconds(10),
expirationType: WeakenedCache.ExpirationType.Weaken);

Or Clear type

var otherInstance = new SampleRefType();

cache.Put(
key: Key5,
value: otherInstance,
priority: WeakenedCache.Priority.Normal,
expiration: TimeSpan.FromSeconds(10),
expirationType: WeakenedCache.ExpirationType.Clear);

About

Item cache that makes entries weakly referenced on demand

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Contributors

Languages