Using 'HttpContext.Current.Cache' safely

前端 未结 3 1982
小蘑菇
小蘑菇 2021-02-13 06:57

I am using Cache in a web service method like this:

var pblDataList = (List)HttpContext.Current.Cache.Get(\"pblDataList\");

if (pblDa         


        
3条回答
  •  孤城傲影
    2021-02-13 07:50

    You are correct. The retrieving and adding operations are not being treated as an atomic transaction. If you need to prevent the query from running multiple times, you'll need to use a lock.

    (Normally this wouldn't be much of a problem, but in the case of a long running query it can be useful to relieve strain on the database.)

提交回复
热议问题