[runtime] Disable some tests in full-aot mode which cannot be AOTed because of type...
[mono.git] / mcs / class / monodoc / Monodoc / cache.cs
1 using System;
2 using System.Linq;
3 using System.IO;
4 using System.Configuration;
5 using System.Collections.Specialized;
6 using Monodoc.Caches;
7
8 namespace Monodoc
9 {
10         public enum DocEntity
11         {
12                 Text,
13                 Blob
14         }
15
16         public interface IDocCache : IDisposable
17         {
18                 bool IsCached (string id);
19                 bool CanCache (DocEntity entity);
20
21                 Stream GetCachedStream (string id);
22                 string GetCachedString (string id);
23
24                 void CacheText (string id, string content);
25                 void CacheText (string id, Stream stream);
26
27                 void CacheBlob (string id, byte[] data);
28                 void CacheBlob (string id, Stream stream);
29         }
30
31         public static class DocCacheHelper
32         {
33                 static string cacheBaseDirectory;
34
35                 static DocCacheHelper ()
36                 {
37                         try {
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));
43                         } catch {}
44                 }
45
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)
48                 {
49                         if (cacheBaseDirectory == null)
50                                 return new NullCache ();
51
52                         return new FileCache (Path.Combine (cacheBaseDirectory, name));
53                 }
54         }
55 }