PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.SingleItemCache< T > Class Template Reference

SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided TTL. More...

Inheritance diagram for PeanutButter.Utils.SingleItemCache< T >:
PeanutButter.Utils.ISingleItemCache< T >

Public Member Functions

 SingleItemCache (Func< T > generator, TimeSpan timeToLive)
 SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided TTL.
 
 SingleItemCache (Func< T > generator, Func< TimeSpan > ttlGenerator)
 SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided function to produce a TTL for the data. The ttlGenerator will be called on every access, so it's highly recommended to make it performant.
 
 SingleItemCache (Func< T > generator, Func< bool > cacheInvalidator)
 SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided function to test if the cache should be invalidated before each read.
 
void Invalidate ()
 Invalidates the cache such that the next call will definitely regenerate the value.
 

Properties

T Value [get]
 The value for the generator, or a cached value, if available and still fresh enough.
 
Func< T > Generator [get]
 Expose the generator (might be useful for testing purposes)
 
TimeSpan TimeToLive [get]
 Expose the provided TimeToLive (might be useful for testing purposes)
 
Func< bool > CacheInvalidator [get]
 When provided via the alternative constructor.
 
- Properties inherited from PeanutButter.Utils.ISingleItemCache< T >

Detailed Description

SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided TTL.

Constructor & Destructor Documentation

◆ SingleItemCache() [1/3]

PeanutButter.Utils.SingleItemCache< T >.SingleItemCache ( Func< T >  generator,
TimeSpan  timeToLive 
)

SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided TTL.

Parameters
generator
timeToLive
Exceptions
NotImplementedException

◆ SingleItemCache() [2/3]

PeanutButter.Utils.SingleItemCache< T >.SingleItemCache ( Func< T >  generator,
Func< TimeSpan >  ttlGenerator 
)

SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided function to produce a TTL for the data. The ttlGenerator will be called on every access, so it's highly recommended to make it performant.

Parameters
generator
ttlGenerator

◆ SingleItemCache() [3/3]

PeanutButter.Utils.SingleItemCache< T >.SingleItemCache ( Func< T >  generator,
Func< bool >  cacheInvalidator 
)

SingleItemCache provides a light, fast, caching wrapper around a function to generate a value with a provided function to test if the cache should be invalidated before each read.

Parameters
generator
cacheInvalidator

Member Function Documentation

◆ Invalidate()

void PeanutButter.Utils.SingleItemCache< T >.Invalidate ( )

Invalidates the cache such that the next call will definitely regenerate the value.

Exceptions
NotImplementedException

Implements PeanutButter.Utils.ISingleItemCache< T >.

Property Documentation

◆ Generator

Func<T> PeanutButter.Utils.SingleItemCache< T >.Generator
get

Expose the generator (might be useful for testing purposes)

Implements PeanutButter.Utils.ISingleItemCache< T >.

◆ TimeToLive

TimeSpan PeanutButter.Utils.SingleItemCache< T >.TimeToLive
get

Expose the provided TimeToLive (might be useful for testing purposes)

Implements PeanutButter.Utils.ISingleItemCache< T >.

◆ Value

The value for the generator, or a cached value, if available and still fresh enough.

Implements PeanutButter.Utils.ISingleItemCache< T >.


The documentation for this class was generated from the following file: