mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-11-23 20:25:00 +00:00
improve cache file size check
This commit is contained in:
parent
c7658647fc
commit
b980ea837b
2
src/main/java/dev/plex/cache/CacheItem.java
vendored
2
src/main/java/dev/plex/cache/CacheItem.java
vendored
@ -13,7 +13,7 @@ public class CacheItem
|
|||||||
public CacheItem(File f) throws IOException
|
public CacheItem(File f) throws IOException
|
||||||
{
|
{
|
||||||
this.path = f.getPath();
|
this.path = f.getPath();
|
||||||
this.file = Files.readAllBytes(f.toPath());
|
this.file = f.length() >= 1048576 ? null : Files.readAllBytes(f.toPath());
|
||||||
this.timestamp = System.currentTimeMillis();
|
this.timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
src/main/java/dev/plex/cache/FileCache.java
vendored
4
src/main/java/dev/plex/cache/FileCache.java
vendored
@ -21,13 +21,13 @@ public class FileCache
|
|||||||
if (theItem == null)
|
if (theItem == null)
|
||||||
{
|
{
|
||||||
theItem = new CacheItem(new File(path));
|
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
|
if (System.currentTimeMillis() - theItem.timestamp > 3 * 60 * 1000) // 3 minutes
|
||||||
{
|
{
|
||||||
cache.remove(theItem);
|
cache.remove(theItem);
|
||||||
theItem = new CacheItem(new File(path));
|
theItem = new CacheItem(new File(path));
|
||||||
if (theItem.file.length < 1048576) cache.add(theItem);
|
if (theItem.file != null) cache.add(theItem);
|
||||||
}
|
}
|
||||||
return theItem.file;
|
return theItem.file;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,8 @@ public class SchematicEndpoint extends AbstractServlet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
outputStream.write(HTTPDModule.fileCache.getFile(schemFile));
|
byte[] schemData = HTTPDModule.fileCache.getFile(schemFile);
|
||||||
|
if (schemData != null) outputStream.write(schemData);
|
||||||
}
|
}
|
||||||
catch (IOException ignored)
|
catch (IOException ignored)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user