T
- a Throwable
that may be thrown during updateData()
,
use RuntimeException
if no exception must be handled.public abstract class CacheCustomContent<T extends java.lang.Throwable> extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private byte[] |
data
Where the data will be stored
|
private java.lang.String |
ident
The ident that identifies the stored file.
|
static int |
INTERVAL_ALWAYS
Common intervals
|
static int |
INTERVAL_DAILY |
static int |
INTERVAL_HOURLY |
static int |
INTERVAL_MONTHLY |
static int |
INTERVAL_NEVER |
static int |
INTERVAL_WEEKLY |
private java.io.File |
path
The (file-)path where the data will be stored
|
private int |
updateInterval
How often to update the cached version
|
Constructor and Description |
---|
CacheCustomContent(java.lang.String ident,
int updateInterval)
Initializes the class.
|
Modifier and Type | Method and Description |
---|---|
void |
flushData()
Flushes the data from memory.
|
byte[] |
getData()
Returns the data without performing any updates
|
java.lang.String |
getDataString()
Returns the data without performing any updates
|
protected boolean |
isCacheValid()
This function serves as a comfort hook to perform additional checks if the cache is valid
|
private void |
loadFromDisk()
Tries to load the data using the given ident from disk.
|
private void |
saveToDisk()
Stores the data to disk
|
protected abstract byte[] |
updateData()
This function will be executed when an update is required.
|
byte[] |
updateForce()
Executes an update regardless of updateInterval
|
java.lang.String |
updateForceString()
Executes an update regardless of updateInterval
|
byte[] |
updateIfRequired()
Updates data if required
|
java.lang.String |
updateIfRequiredString()
Updates data if required
|
public static final int INTERVAL_ALWAYS
public static final int INTERVAL_HOURLY
public static final int INTERVAL_DAILY
public static final int INTERVAL_WEEKLY
public static final int INTERVAL_MONTHLY
public static final int INTERVAL_NEVER
private byte[] data
private final java.lang.String ident
private final java.io.File path
private final int updateInterval
public CacheCustomContent(java.lang.String ident, int updateInterval)
ident
- updateInterval
- protected abstract byte[] updateData() throws T extends java.lang.Throwable
T extends java.lang.Throwable
protected boolean isCacheValid()
public byte[] updateIfRequired() throws T extends java.lang.Throwable
T extends java.lang.Throwable
public java.lang.String updateIfRequiredString() throws T extends java.lang.Throwable
T extends java.lang.Throwable
public byte[] updateForce() throws T extends java.lang.Throwable
T extends java.lang.Throwable
public java.lang.String updateForceString() throws T extends java.lang.Throwable
T extends java.lang.Throwable
public byte[] getData() throws T extends java.lang.Throwable
T extends java.lang.Throwable
public java.lang.String getDataString() throws T extends java.lang.Throwable
T extends java.lang.Throwable
private void loadFromDisk() throws T extends java.lang.Throwable
T extends java.lang.Throwable
private void saveToDisk()
public void flushData()