public class CacheFiles extends Object
Modifier and Type | Field and Description |
---|---|
static int |
CLEAN_ALL |
static int |
CLEAN_BY_DATE |
static int |
CLEAN_SMALL_FILES |
private static int |
CLEANUP_INTERVAL |
private static int |
CLEANUP_TRESHOLD |
private File |
dir |
private boolean |
enabled |
private long |
expire |
static int |
EXPIRE_DAILY |
static int |
EXPIRE_MONTHLY |
static int |
EXPIRE_NEVER
Common expirey dates
|
static int |
EXPIRE_WEEKLY |
private String |
ident |
private long |
maxsize |
private boolean |
updateModTime |
private int |
writes |
Constructor and Description |
---|
CacheFiles(String ident)
Creates a new cache class.
|
CacheFiles(String ident,
boolean isPlugin)
Creates a new cache class.
|
Modifier and Type | Method and Description |
---|---|
void |
checkCleanUp()
Checks if a clean up is needed and will do so if necessary
|
void |
cleanUp()
Performs a default clean up with the set values (deletes oldest files first)
|
void |
customCleanUp(int type,
int size)
Performs a non-default, specified clean up
|
byte[] |
getData(String ident)
Loads the data for the given ident as an byte array.
|
private long |
getDirSize()
Calculates the size of the directory
|
BufferedImage |
getImg(String ident)
Loads the data for the given ident as an image.
|
private File |
getPath(String ident)
Gets file path for ident
|
private File |
getPath(String ident,
String ending)
Gets file path for ident with customizable file-ending
|
private static String |
getUniqueFilename(String ident)
Returns a short and unique file name for a given long identifier
|
private boolean |
isExpired(File file)
Checks whether a given file is expired
|
void |
saveData(String ident,
byte[] data)
Writes an byte-array to disk
|
void |
saveImg(String ident,
BufferedImage image)
Saves a given image and ident to the cache
|
void |
setExpire(int amount,
boolean force)
Sets the amount of time data is stored before it gets expired
|
void |
setMaxSize(int amount,
boolean force)
Sets the amount of data stored in the cache
|
void |
setUpdateModTime(boolean to)
Call this with
true to update the last modification time when a file it is read. |
public static final int EXPIRE_NEVER
public static final int EXPIRE_DAILY
public static final int EXPIRE_WEEKLY
public static final int EXPIRE_MONTHLY
private final boolean enabled
private long expire
private long maxsize
private boolean updateModTime
private static final int CLEANUP_TRESHOLD
private static final int CLEANUP_INTERVAL
private int writes
public static final int CLEAN_ALL
public static final int CLEAN_SMALL_FILES
public static final int CLEAN_BY_DATE
public CacheFiles(String ident)
true
.ident
- cache identifierpublic CacheFiles(String ident, boolean isPlugin)
ident
- cache identifierisPlugin
- Whether this is a plugin or not (changes cache path)public byte[] getData(String ident)
ident
- cache identifierpublic void saveData(String ident, byte[] data)
ident
- cache identifierdata
- data to storepublic BufferedImage getImg(String ident)
ident
- cache identifierpublic void saveImg(String ident, BufferedImage image)
ident
- cache identifierimage
- imaga data for storagepublic void setExpire(int amount, boolean force)
amount
- of time in secondsforce
- will also write it to the preferencespublic void setMaxSize(int amount, boolean force)
amount
- in Megabytesforce
- will also write it to the preferencespublic void setUpdateModTime(boolean to)
true
to update the last modification time when a file it is read.
Call this with false
to not update the last modification time when a file is read.to
- update statepublic void checkCleanUp()
public void cleanUp()
public void customCleanUp(int type, int size)
type
- any of the CLEAN_XX constants.size
- for CLEAN_SMALL_FILES: deletes all files smaller than (size) bytesprivate long getDirSize()
private static String getUniqueFilename(String ident)
private File getPath(String ident, String ending)
ident
- cache identifierending
- file extensionprivate File getPath(String ident)
ident
- cache identifier