c# - Generic implementation of System.Runtime.Caching.MemoryCache -
is there generic alternative / implementation memorycache?
i know memorycache uses hashtable under hood, take transition using dictionary<,>, generic version of hashtable.
this provide type safety , provide performance benefits no boxing/unboxing.
edit: thing i'm interested in having different key type. default system.string.
is there generic alternative / implementation memorycache?
not in base class library. you'd have roll own, though i, personally, make wrapper around memorycache
provides api wish.
this provide type safety , provide performance benefits no boxing/unboxing
the type safety can handled in wrapper class. boxing/unboxing issue if storing value types (not classes), , then, minimal, it's unlikely you're pushing , pulling cache enough have true performance issue.
as type safety , usability, i've written own methods wrap memorycache
item's calls in generic method, allows bit nicer usage api standpoint. easy - typically requires method like:
public t getitem<t>(string key) t : class { return memorycache[key] t; }
similarly, can make method set values same way.
edit: thing i'm interested in having different key type. default system.string.
this not supported directly memorycache
, require fair bit of work make own key generation. 1 option make type safe wrapper provided func<t, string>
generate string key based off value - allow generate cache entry type t
. you'd have careful, of course, include data in string wanted part of comparison, however.
Comments
Post a Comment