source: binary-improvements2/7dtd-server-fixes/src/FileCache/SimpleCache.cs@ 391

Last change on this file since 391 was 391, checked in by alloc, 2 years ago

Major refactoring/cleanup

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