4 using System.Configuration;
5 using System.Collections.Specialized;
16 public interface IDocCache : IDisposable
18 bool IsCached (string id);
19 bool CanCache (DocEntity entity);
21 Stream GetCachedStream (string id);
22 string GetCachedString (string id);
24 void CacheText (string id, string content);
25 void CacheText (string id, Stream stream);
27 void CacheBlob (string id, byte[] data);
28 void CacheBlob (string id, Stream stream);
31 public static class DocCacheHelper
33 static string cacheBaseDirectory;
35 static DocCacheHelper ()
38 var cacheValues = Config.Get ("cache").Split (',');
39 if (cacheValues.Length == 2 && cacheValues[0].Equals ("file", StringComparison.Ordinal))
40 cacheBaseDirectory = cacheValues[1].Replace ("~", Environment.GetFolderPath (Environment.SpecialFolder.Personal));
44 // Use configuration option to query for cache directory, if it doesn't exist we instantiate a nullcache
45 public static IDocCache GetDefaultCache (string name)
47 if (cacheBaseDirectory == null)
48 return new NullCache ();
50 return new FileCache (Path.Combine (cacheBaseDirectory, name));