source: binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs@ 254

Last change on this file since 254 was 199, checked in by alloc, 10 years ago

fixes

File size: 763 bytes
RevLine 
[199]1using System;
2using System.Collections.Generic;
3using System.IO;
4
5namespace AllocsFixes.FileCache
6{
7 // Caching all files, useful for completely static folders only
8 public class SimpleCache : AbstractCache
9 {
10
11 private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> ();
12
13 public SimpleCache ()
14 {
15 }
16
17 public override byte[] GetFileContent (string filename)
18 {
19 try {
20 lock (fileCache) {
21 if (!fileCache.ContainsKey (filename)) {
22 if (!File.Exists (filename)) {
23 return null;
24 }
25
26 fileCache.Add (filename, File.ReadAllBytes (filename));
27 }
28
29 return fileCache [filename];
30 }
31 } catch (Exception e) {
32 Log.Out ("Error in SimpleCache.GetFileContent: " + e);
33 }
34 return null;
35 }
36
37 }
38}
39
Note: See TracBrowser for help on using the repository browser.