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