andrew4582

SetResponseCachePolicy

Mar 10th, 2011
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. void SetResponseCachePolicy(string filePath,HttpResponse response) {
  2. #if DEBUG
  3.                 bool IsDebug = true;
  4. #else
  5.                 bool IsDebug = false;
  6. #endif
  7.                 if(IsDebug) {
  8.                     response.Cache.SetCacheability(HttpCacheability.NoCache);
  9.                 }
  10.                 else {
  11.                     HttpCachePolicy cachePolicy = response.Cache;
  12.                     string etag = Math.Abs(filePath.GetHashCode()).ToString();
  13.                     cachePolicy.SetCacheability(HttpCacheability.Public);
  14.                     cachePolicy.SetOmitVaryStar(true);
  15.                     cachePolicy.SetExpires(DateTime.Now.AddDays(730));
  16.                     cachePolicy.SetValidUntilExpires(true);
  17.                     cachePolicy.SetLastModifiedFromFileDependencies();
  18.                     cachePolicy.SetETag(etag);
  19.                 }
  20.             }
Advertisement
Add Comment
Please, Sign In to add comment