Index: /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
===================================================================
--- /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 199)
@@ -125,4 +125,8 @@
     <Compile Include="src\CustomCommands\Unban.cs" />
     <Compile Include="src\ItemList.cs" />
+    <Compile Include="src\FileCache\AbstractCache.cs" />
+    <Compile Include="src\FileCache\DirectAccess.cs" />
+    <Compile Include="src\FileCache\SimpleCache.cs" />
+    <Compile Include="src\FileCache\MapTileCache.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@@ -138,4 +142,5 @@
     <Folder Include="src\NetConnections\Servers\Web\API\" />
     <Folder Include="src\JSON\Parser\" />
+    <Folder Include="src\FileCache\" />
   </ItemGroup>
 </Project>
Index: /binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs	(revision 199)
+++ /binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs	(revision 199)
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace AllocsFixes.FileCache
+{
+	public abstract class AbstractCache
+	{
+
+		public AbstractCache ()
+		{
+		}
+
+		public abstract byte[] GetFileContent (string filename);
+
+	}
+}
+
Index: /binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs	(revision 199)
+++ /binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs	(revision 199)
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace AllocsFixes.FileCache
+{
+	// Not caching at all, simply reading from disk on each request
+	public class DirectAccess : AbstractCache
+	{
+
+		public DirectAccess ()
+		{
+		}
+
+		public override byte[] GetFileContent (string filename)
+		{
+			try {
+				if (!File.Exists (filename)) {
+					return null;
+				}
+
+				return File.ReadAllBytes (filename);
+			} catch (Exception e) {
+				Log.Out ("Error in DirectAccess.GetFileContent: " + e);
+			}
+			return null;
+		}
+
+	}
+}
+
Index: /binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs	(revision 199)
+++ /binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs	(revision 199)
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace AllocsFixes.FileCache
+{
+	// Special "cache" for map tile folder as both map rendering and webserver access files in there.
+	// Only map rendering tiles are cached. Writing is done by WriteThrough.
+	public class MapTileCache : AbstractCache
+	{
+		private struct CurrentZoomFile
+		{
+			public string filename;
+			public byte[] data;
+		}
+
+		private CurrentZoomFile[] cache;
+
+		public MapTileCache ()
+		{
+		}
+
+		public void SetZoomCount (int count)
+		{
+			cache = new CurrentZoomFile[count];
+		}
+
+		public byte[] LoadTile (int zoomlevel, string filename)
+		{
+			try {
+				lock (cache) {
+					if (cache [zoomlevel].filename == null || !cache [zoomlevel].filename.Equals (filename)) {
+						cache [zoomlevel].filename = filename;
+
+						if (!File.Exists (filename)) {
+							cache [zoomlevel].data = null;
+							return null;
+						}
+
+						cache [zoomlevel].data = File.ReadAllBytes (filename);
+					}
+					return cache [zoomlevel].data;
+				}
+			} catch (Exception e) {
+				Log.Out ("Error in MapTileCache.LoadTile: " + e);
+			}
+			return null;
+		}
+
+		public void SaveTile (int zoomlevel, byte[] content)
+		{
+			try {
+				lock (cache) {
+					if (cache [zoomlevel].filename != null) {
+						cache [zoomlevel].data = content;
+						File.WriteAllBytes (cache [zoomlevel].filename, content);
+					}
+				}
+			} catch (Exception e) {
+				Log.Out ("Error in MapTileCache.SaveTile: " + e);
+			}
+		}
+
+		public override byte[] GetFileContent (string filename)
+		{
+			try {
+				lock (cache) {
+					foreach (CurrentZoomFile czf in cache) {
+						if (czf.filename != null && czf.filename.Equals (filename))
+							return czf.data;
+					}
+
+					if (!File.Exists (filename)) {
+						return null;
+					}
+					return File.ReadAllBytes (filename);
+				}
+			} catch (Exception e) {
+				Log.Out ("Error in MapTileCache.GetFileContent: " + e);
+			}
+			return null;
+		}
+
+	}
+}
+
Index: /binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs	(revision 199)
+++ /binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs	(revision 199)
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace AllocsFixes.FileCache
+{
+	// Caching all files, useful for completely static folders only
+	public class SimpleCache : AbstractCache
+	{
+
+		private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> ();
+
+		public SimpleCache ()
+		{
+		}
+
+		public override byte[] GetFileContent (string filename)
+		{
+			try {
+				lock (fileCache) {
+					if (!fileCache.ContainsKey (filename)) {
+						if (!File.Exists (filename)) {
+							return null;
+						}
+
+						fileCache.Add (filename, File.ReadAllBytes (filename));
+					}
+
+					return fileCache [filename];
+				}
+			} catch (Exception e) {
+				Log.Out ("Error in SimpleCache.GetFileContent: " + e);
+			}
+			return null;
+		}
+
+	}
+}
+
Index: /binary-improvements/7dtd-server-fixes/src/ItemList.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/ItemList.cs	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/src/ItemList.cs	(revision 199)
@@ -49,8 +49,9 @@
 				string name = ib.GetItemName (invF.itemValue);
 				if (name != null && name.Length > 0) {
-					if (!items.ContainsKey (name))
+					if (!items.ContainsKey (name)) {
 						items.Add (name, invF.itemValue);
-					else
-						Log.Out ("Item \"" + name + "\" already in list!");
+					} else {
+						//Log.Out ("Item \"" + name + "\" already in list!");
+					}
 				}
 			}
@@ -59,8 +60,9 @@
 				string name = ib.GetItemName (invF.itemValue);
 				if (name != null && name.Length > 0) {
-					if (!items.ContainsKey (name))
+					if (!items.ContainsKey (name)) {
 						items.Add (name, invF.itemValue);
-					else
-						Log.Out ("Item \"" + name + "\" already in list!");
+					} else {
+						//Log.Out ("Item \"" + name + "\" already in list!");
+					}
 				}
 			}
Index: /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRenderBlockBuffer.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRenderBlockBuffer.cs	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRenderBlockBuffer.cs	(revision 199)
@@ -13,8 +13,10 @@
 		private Texture2D zoomBuffer = new Texture2D (1, 1);
 		private Color nullColor = new Color (0, 0, 0, 0);
+		private AllocsFixes.FileCache.MapTileCache cache;
 
-		public MapRenderBlockBuffer (int level)
+		public MapRenderBlockBuffer (int level, AllocsFixes.FileCache.MapTileCache cache)
 		{
 			zoomLevel = level;
+			this.cache = cache;
 		}
 
@@ -68,8 +70,12 @@
 		private void loadTextureFromFile (string _fileName)
 		{
-			try {
-				byte[] array = File.ReadAllBytes (_fileName);
+			byte[] array = cache.LoadTile (zoomLevel, _fileName);
+			if (array != null) {
 				blockMap.LoadImage (array);
-			} catch (Exception) {
+			} else {
+				//try {
+				//byte[] array = File.ReadAllBytes (_fileName);
+				//blockMap.LoadImage (array);
+				//} catch (Exception) {
 				for (int x = 0; x < Constants.MAP_BLOCK_SIZE; x++) {
 					for (int y = 0; y < Constants.MAP_BLOCK_SIZE; y++) {
@@ -82,10 +88,12 @@
 		private void saveTextureToFile (string _fileName)
 		{
-			try {
-				byte[] array = blockMap.EncodeToPNG ();
-				File.WriteAllBytes (_fileName, array);
-			} catch (Exception e) {
-				Log.Out ("Exception in MapRenderBlockBuffer.saveTextureToFile(): " + e);
-			}
+			byte[] array = blockMap.EncodeToPNG ();
+			cache.SaveTile (zoomLevel, array);
+//			try {
+//				byte[] array = blockMap.EncodeToPNG ();
+//				File.WriteAllBytes (_fileName, array);
+//			} catch (Exception e) {
+//				Log.Out ("Exception in MapRenderBlockBuffer.saveTextureToFile(): " + e);
+//			}
 		}
 
Index: /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs	(revision 199)
@@ -29,4 +29,9 @@
 		public static bool renderingEnabled = true;
 		private MicroStopwatch msw = new MicroStopwatch ();
+		private AllocsFixes.FileCache.MapTileCache cache = new AllocsFixes.FileCache.MapTileCache ();
+
+		public AllocsFixes.FileCache.MapTileCache TileCache {
+			get { return cache; }
+		}
 
 		private MapRendering ()
@@ -39,7 +44,9 @@
 			}
 
+			cache.SetZoomCount (Constants.ZOOMLEVELS);
+
 			zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS];
 			for (int i = 0; i < Constants.ZOOMLEVELS; i++) {
-				zoomLevelBuffers [i] = new MapRenderBlockBuffer (i);
+				zoomLevelBuffers [i] = new MapRenderBlockBuffer (i, cache);
 			}
 
Index: /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs	(revision 199)
@@ -11,9 +11,8 @@
 		private string datapath;
 		private string staticPart;
-		private bool cache;
+		private AllocsFixes.FileCache.AbstractCache cache;
 		private bool logMissingFiles;
-		private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> ();
 
-		public StaticHandler (string staticPart, string filePath, bool cache, bool logMissingFiles)
+		public StaticHandler (string staticPart, string filePath, AllocsFixes.FileCache.AbstractCache cache, bool logMissingFiles)
 		{
 			this.staticPart = staticPart;
@@ -28,33 +27,15 @@
 				string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length);
 
-				byte[] content;
-				if (cache) {
-					lock (fileCache) {
-						if (!fileCache.ContainsKey (fn)) {
-							if (!File.Exists (datapath + "/" + fn)) {
-								throw new FileNotFoundException ();
-							}
-
-							fileCache.Add (fn, File.ReadAllBytes (datapath + "/" + fn));
-						}
-
-						content = fileCache [fn];
-					}
+				byte[] content = cache.GetFileContent (datapath + "/" + fn);
+				if (content != null) {
+					resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn));
+					resp.ContentLength64 = content.Length;
+					resp.OutputStream.Write (content, 0, content.Length);
 				} else {
-					if (!File.Exists (datapath + "/" + fn)) {
-						throw new FileNotFoundException ();
-					}
-
-					content = File.ReadAllBytes (datapath + "/" + fn);
+					resp.StatusCode = (int)HttpStatusCode.NotFound;
+					if (logMissingFiles)
+						Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\"");
+					return;
 				}
-
-				resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn));
-				resp.ContentLength64 = content.Length;
-				resp.OutputStream.Write (content, 0, content.Length);
-			} catch (FileNotFoundException) {
-				resp.StatusCode = (int)HttpStatusCode.NotFound;
-				if (logMissingFiles)
-					Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\"");
-				return;
 			} catch (Exception e) {
 				Log.Out ("Error in StaticHandler.HandleRequest: " + e);
Index: /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs	(revision 198)
+++ /binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs	(revision 199)
@@ -34,7 +34,23 @@
 				}
  
-				handlers.Add ("/index.htm", new SimpleRedirectHandler ("/static/index.html"));
-				handlers.Add ("/static/", new StaticHandler ("/static/", Application.dataPath + "/../webserver", false/*true*/, true)); // TODO: Enable cache
-				handlers.Add ("/map/", new StaticHandler ("/map/", StaticDirectories.GetSaveGameDir () + "/map", false, false));
+				handlers.Add (
+						"/index.htm",
+						new SimpleRedirectHandler ("/static/index.html"));
+				handlers.Add (
+						"/static/",
+						new StaticHandler (
+								"/static/",
+								Application.dataPath + "/../webserver",
+								new AllocsFixes.FileCache.DirectAccess (),
+								true)
+				); // TODO: Enable cache
+				handlers.Add (
+						"/map/",
+						new StaticHandler (
+								"/map/",
+								StaticDirectories.GetSaveGameDir () + "/map",
+								MapRendering.MapRendering.Instance.TileCache,
+								false)
+				);
 				handlers.Add ("/api/", new ApiHandler ("/api/"));
 
@@ -61,5 +77,5 @@
 				);
 
-				NetTelnetServer.RegisterServer(this);
+				NetTelnetServer.RegisterServer (this);
 
 
Index: /binary-improvements/bin/Release/7dtd-server-fixes_version.txt
===================================================================
--- /binary-improvements/bin/Release/7dtd-server-fixes_version.txt	(revision 198)
+++ /binary-improvements/bin/Release/7dtd-server-fixes_version.txt	(revision 199)
@@ -1,1 +1,1 @@
-Version:       0.93.5378.21429
+Version:       0.93.5378.41731
