T
- a Throwable
that may be thrown during updateData()
,
use RuntimeException
if no exception must be handled.public abstract class CacheCustomContent<T extends Throwable> extends Object
Modifier and Type | Field and Description |
---|---|
private byte[] |
data
Where the data will be stored
|
private 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 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(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
|
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
|
String |
updateForceString()
Executes an update regardless of updateInterval
|
byte[] |
updateIfRequired()
Updates data if required
|
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 int updateInterval
public CacheCustomContent(String ident, int updateInterval)
ident
- updateInterval
- protected abstract byte[] updateData() throws T extends Throwable
protected boolean isCacheValid()
public byte[] updateIfRequired() throws T extends Throwable
public String updateIfRequiredString() throws T extends Throwable
public byte[] updateForce() throws T extends Throwable
public String updateForceString() throws T extends Throwable
public byte[] getData() throws T extends Throwable
public String getDataString() throws T extends Throwable
private void loadFromDisk() throws T extends Throwable
private void saveToDisk()
public void flushData()