1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Diagnostics.CodeAnalysis;
\r
16 using System.Web.Caching;
\r
17 using System.Web.Mvc.Resources;
\r
19 [SuppressMessage("Microsoft.Security", "CA2112:SecuredTypesShouldNotExposeFields",
\r
20 Justification = "The Null field does not have access to secure information")]
\r
21 public class DefaultViewLocationCache : IViewLocationCache {
\r
22 private static readonly TimeSpan _defaultTimeSpan = new TimeSpan(0, 15, 0);
\r
24 public DefaultViewLocationCache()
\r
25 : this(_defaultTimeSpan) {
\r
28 public DefaultViewLocationCache(TimeSpan timeSpan) {
\r
29 if (timeSpan.Ticks < 0) {
\r
30 throw new InvalidOperationException(MvcResources.DefaultViewLocationCache_NegativeTimeSpan);
\r
32 TimeSpan = timeSpan;
\r
35 [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
\r
36 Justification = "The reference type is immutable. ")]
\r
37 public static readonly IViewLocationCache Null = new NullViewLocationCache();
\r
39 public TimeSpan TimeSpan {
\r
44 #region IViewLocationCache Members
\r
45 public string GetViewLocation(HttpContextBase httpContext, string key) {
\r
46 if (httpContext == null) {
\r
47 throw new ArgumentNullException("httpContext");
\r
49 return (string)httpContext.Cache[key];
\r
52 public void InsertViewLocation(HttpContextBase httpContext, string key, string virtualPath) {
\r
53 if (httpContext == null) {
\r
54 throw new ArgumentNullException("httpContext");
\r
56 httpContext.Cache.Insert(key, virtualPath, null /* dependencies */, Cache.NoAbsoluteExpiration, TimeSpan);
\r