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 cacheConfig = Config.Get ("cache");
39 if (cacheConfig == null) return;
40 var cacheValues = cacheConfig.Split (',');
41 if (cacheValues.Length == 2 && cacheValues[0].Equals ("file", StringComparison.Ordinal))
42 cacheBaseDirectory = cacheValues[1].Replace ("~", Environment.GetFolderPath (Environment.SpecialFolder.Personal));
46 // Use configuration option to query for cache directory, if it doesn't exist we instantiate a nullcache
47 public static IDocCache GetDefaultCache (string name)
49 if (cacheBaseDirectory == null)
50 return new NullCache ();
52 return new FileCache (Path.Combine (cacheBaseDirectory, name));