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
Update interval meaning an update is always needed
|
static int |
INTERVAL_DAILY
Update interval meaning an update is needed each day
|
static int |
INTERVAL_HOURLY
Update interval meaning an update is needed each hour
|
static int |
INTERVAL_MONTHLY
Update interval meaning an update is needed each month
|
static int |
INTERVAL_NEVER
Update interval meaning an update is never needed
|
static int |
INTERVAL_WEEKLY
Update interval meaning an update is needed each week
|
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 |
---|---|
protected abstract void |
checkOfflineAccess()
Ensures underlying resource is not accessed in offline mode.
|
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 boolean |
isOffline() |
private void |
loadFromDisk()
Tries to load the data using the given ident from disk.
|
private boolean |
needsUpdate() |
private void |
saveToDisk()
Stores the data to disk
|
protected abstract byte[] |
updateData()
This function will be executed when an update is required.
|
private 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
- ident that identifies the stored file. Includes file-ending.updateInterval
- update interval in seconds. -1 means alwaysprotected abstract byte[] updateData() throws T extends java.lang.Throwable
T
- a Throwable
T extends java.lang.Throwable
protected boolean isCacheValid()
private boolean needsUpdate()
private boolean isOffline()
protected abstract void checkOfflineAccess()
OfflineAccessException
- if resource is accessed in offline modepublic byte[] updateIfRequired() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
public java.lang.String updateIfRequiredString() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
private byte[] updateForce() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
public java.lang.String updateForceString() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
public byte[] getData() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
public java.lang.String getDataString() throws T extends java.lang.Throwable
T
- if an error occursT extends java.lang.Throwable
private void loadFromDisk() throws T extends java.lang.Throwable
T
- a Throwable
T extends java.lang.Throwable
private void saveToDisk()
public void flushData()