How to set different Cache expire times for Client and Server caches

后端 未结 3 1064
暗喜
暗喜 2021-02-07 16:33

I would like to have certain pages have a 10 minute Cache for clients and 24 hours for the server. The reason is if the page changes, the client will fetch the updated version w

3条回答
  •  忘了有多久
    2021-02-07 17:17

    You need to implement your own solution for server side caching and for client side caching either use ClientCacheAttribute or OutputCache. Here are the reason for why you would require your custom solution for server side cache.

    • ClientCacheAttribute sets cache policy to Response.Cache which is type of HttpCachePolicyBase
    • and built-in OutputCache also sets cache policy to Response.Cache

    Here what I'm trying to highlight is that we don't have collection of HttpCachePolicyBase but we only have one object of HttpCachePolicyBase so we can't set multiple cache policy for given response.

    Even if we can set Http Cacheability to HttpCacheability.ServerAndPrivate but again you will run in other issue with cache duration (i.e. for client 10 minute & server 24 hours)

    What I would suggest is that use OutputCache for client side caching and implement your own caching mechanism for server side caching.

提交回复
热议问题