Changeset 351 for binary-improvements/7dtd-server-fixes/src/FileCache
- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src/FileCache
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs
r325 r351 1 1 namespace AllocsFixes.FileCache { 2 2 public abstract class AbstractCache { 3 public abstract byte[] GetFileContent (string filename);3 public abstract byte[] GetFileContent (string _filename); 4 4 } 5 5 } -
binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs
r325 r351 5 5 // Not caching at all, simply reading from disk on each request 6 6 public class DirectAccess : AbstractCache { 7 public override byte[] GetFileContent (string filename) {7 public override byte[] GetFileContent (string _filename) { 8 8 try { 9 if (!File.Exists ( filename)) {9 if (!File.Exists (_filename)) { 10 10 return null; 11 11 } 12 12 13 return File.ReadAllBytes ( filename);13 return File.ReadAllBytes (_filename); 14 14 } catch (Exception e) { 15 15 Log.Out ("Error in DirectAccess.GetFileContent: " + e); -
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r346 r351 25 25 } 26 26 27 public void SetZoomCount (int count) {28 cache = new CurrentZoomFile[ count];27 public void SetZoomCount (int _count) { 28 cache = new CurrentZoomFile[_count]; 29 29 for (int i = 0; i < cache.Length; i++) { 30 30 cache [i] = new CurrentZoomFile (); … … 32 32 } 33 33 34 public byte[] LoadTile (int zoomlevel, stringfilename) {34 public byte[] LoadTile (int _zoomlevel, string _filename) { 35 35 try { 36 36 lock (cache) { 37 CurrentZoomFile cacheEntry = cache [ zoomlevel];37 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 38 38 39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals ( filename)) {40 cacheEntry.filename = filename;39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals (_filename)) { 40 cacheEntry.filename = _filename; 41 41 42 if (!File.Exists ( filename)) {42 if (!File.Exists (_filename)) { 43 43 cacheEntry.pngData = null; 44 44 return null; … … 46 46 47 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = ReadAllBytes ( filename);48 cacheEntry.pngData = ReadAllBytes (_filename); 49 49 Profiler.EndSample (); 50 50 } … … 59 59 } 60 60 61 public void SaveTile (int zoomlevel, byte[]contentPng) {61 public void SaveTile (int _zoomlevel, byte[] _contentPng) { 62 62 try { 63 63 lock (cache) { 64 CurrentZoomFile cacheEntry = cache [ zoomlevel];64 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 65 65 66 66 string file = cacheEntry.filename; … … 69 69 } 70 70 71 cacheEntry.pngData = contentPng;71 cacheEntry.pngData = _contentPng; 72 72 73 73 Profiler.BeginSample ("WritePng"); 74 74 using (Stream stream = new FileStream (file, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 75 75 4096)) { 76 stream.Write ( contentPng, 0,contentPng.Length);76 stream.Write (_contentPng, 0, _contentPng.Length); 77 77 } 78 78 Profiler.EndSample (); … … 83 83 } 84 84 85 public void ResetTile (int zoomlevel) {85 public void ResetTile (int _zoomlevel) { 86 86 try { 87 87 lock (cache) { 88 cache [ zoomlevel].filename = null;89 cache [ zoomlevel].pngData = null;88 cache [_zoomlevel].filename = null; 89 cache [_zoomlevel].pngData = null; 90 90 } 91 91 } catch (Exception e) { … … 94 94 } 95 95 96 public override byte[] GetFileContent (string filename) {96 public override byte[] GetFileContent (string _filename) { 97 97 try { 98 98 lock (cache) { 99 99 foreach (CurrentZoomFile czf in cache) { 100 if (czf.filename != null && czf.filename.Equals ( filename)) {100 if (czf.filename != null && czf.filename.Equals (_filename)) { 101 101 return czf.pngData; 102 102 } 103 103 } 104 104 105 if (!File.Exists ( filename)) {105 if (!File.Exists (_filename)) { 106 106 return transparentTile; 107 107 } 108 108 109 return ReadAllBytes ( filename);109 return ReadAllBytes (_filename); 110 110 } 111 111 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs
r325 r351 8 8 private readonly Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> (); 9 9 10 public override byte[] GetFileContent (string filename) {10 public override byte[] GetFileContent (string _filename) { 11 11 try { 12 12 lock (fileCache) { 13 if (!fileCache.ContainsKey ( filename)) {14 if (!File.Exists ( filename)) {13 if (!fileCache.ContainsKey (_filename)) { 14 if (!File.Exists (_filename)) { 15 15 return null; 16 16 } 17 17 18 fileCache.Add ( filename, File.ReadAllBytes (filename));18 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 19 19 } 20 20 21 return fileCache [ filename];21 return fileCache [_filename]; 22 22 } 23 23 } catch (Exception e) {
Note:
See TracChangeset
for help on using the changeset viewer.