| Line | |
|---|
| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.IO;
|
|---|
| 4 |
|
|---|
| 5 | namespace 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.