Caching asynchronous operations

后端 未结 6 482
暖寄归人
暖寄归人 2020-12-28 16:40

I am looking for an elegant way of caching the results of my asynchronous operations.

I first had a synchronous method like this:

public String GetSt         


        
6条回答
  •  伪装坚强ぢ
    2020-12-28 17:33

    It's actually reasonable (and depending on your design and performance, crucial) to keep those failed tasks as a Negative Cache. Otherwise, if a url always fails, using it again and again defeats the point of using a cache altogether.

    What you do need is a way to clear the cache from time to time. The simplest way is to have a timer that replaces the ConcurrentDictionarry instance. The more robust solution is to build your own LruDictionary or something similar.

提交回复
热议问题