C#: How to implement a smart cache

后端 未结 6 521
离开以前
离开以前 2021-01-31 05:26

I have some places where implementing some sort of cache might be useful. For example in cases of doing resource lookups based on custom strings, finding names of properties usi

6条回答
  •  -上瘾入骨i
    2021-01-31 05:52

    You could wrap each of your cached items in a WeakReference. This would allow the GC to reclaim items if-and-when required, however it doesn't give you any granular control of when items will disappear from the cache, or allow you to implement explicit expiration policies etc.

    (Ha! I just noticed that the example given on the MSDN page is a simple caching class.)

提交回复
热议问题