improve cache file size check

This commit is contained in:
ayunami2000 2022-04-17 19:54:10 -04:00
parent c7658647fc
commit b980ea837b
3 changed files with 5 additions and 4 deletions

View File

@ -13,7 +13,7 @@ public class CacheItem
public CacheItem(File f) throws IOException
{
this.path = f.getPath();
this.file = Files.readAllBytes(f.toPath());
this.file = f.length() >= 1048576 ? null : Files.readAllBytes(f.toPath());
this.timestamp = System.currentTimeMillis();
}
}

View File

@ -21,13 +21,13 @@ public class FileCache
if (theItem == null)
{
theItem = new CacheItem(new File(path));
if (theItem.file.length < 1048576) cache.add(theItem);
if (theItem.file != null) cache.add(theItem);
}
if (System.currentTimeMillis() - theItem.timestamp > 3 * 60 * 1000) // 3 minutes
{
cache.remove(theItem);
theItem = new CacheItem(new File(path));
if (theItem.file.length < 1048576) cache.add(theItem);
if (theItem.file != null) cache.add(theItem);
}
return theItem.file;
}

View File

@ -67,7 +67,8 @@ public class SchematicEndpoint extends AbstractServlet
{
try
{
outputStream.write(HTTPDModule.fileCache.getFile(schemFile));
byte[] schemData = HTTPDModule.fileCache.getFile(schemFile);
if (schemData != null) outputStream.write(schemData);
}
catch (IOException ignored)
{