ASP.NET Data Cache - preserve contents after app domain restart

后端 未结 3 1961
礼貌的吻别
礼貌的吻别 2021-01-06 07:06

I am using ASP.NET\'s data caching API. For example:

HttpRuntime.Cache.Insert(my_data, my_key);

Is there any way to configure cache so its

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 07:50

    For your most expensive data you can cache the objects with a distributed cache such as Memcached or velocity. Depending on the size of the object and the length of runtime you could also serialize it to disk or to your database provided that the access speed to these resources is less than the time to create the object.

    Now since the in-proc cache is super fast compared to any other solution since it just holds a reference to the memory object you will want to use it where possible. You can keep a copy of your cached object on disk until it is lost and then re-create it from that and place it in memory. Where this is tricky is when you have to expire the data so only use the cache/disk/sql combo where you won't need to expire/invalidate the data otherwise you will need to ensure that you clear both. This will also get around not being able to implement distributed caching on a shared server for example.

提交回复
热议问题