Skip to content

FileCache should provide a AddOrGetExisting method which takes a factory #56

@palenshus

Description

@palenshus

Currently the AddOrGetExisting method takes a value, which requires you to pre-compute the value whether or not the entry is already in the cache. Instead it should take a generator method (Func<T>) which will generate the value in the instance of a cache miss. See https://github.com/alastairtree/LazyCache for an example of this, copied here:

// Declare (but don't execute) a func/delegate whose result we want to cache
Func<ComplexObjects> complexObjectFactory = () => methodThatTakesTimeOrResources();

// Get our ComplexObjects from the cache, or build them in the factory func 
// and cache the results for next time under the given key
ComplexObjects cachedResults = cache.GetOrAdd("uniqueKey", complexObjectFactory);

It should also provide an async overload for this operation as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions