Package org.openstreetmap.josm.io
Class CacheCustomContent<T extends Throwable>
java.lang.Object
org.openstreetmap.josm.io.CacheCustomContent<T>
- Type Parameters:
T- aThrowablethat may be thrown duringupdateData(), useRuntimeExceptionif no exception must be handled.
- Direct Known Subclasses:
CachedAttributionBingAerialTileSource.BingAttributionData,GettingStarted.MotdContent,OsmApi.CapabilitiesCache
Use this class if you want to cache and store a single file that gets updated regularly.
Unless you flush() it will be kept in memory. If you want to cache a lot of data and/or files, use CacheFiles.
- Since:
- 1450
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Where the data will be storedprivate final StringThe ident that identifies the stored file.static final intUpdate interval meaning an update is always neededstatic final intUpdate interval meaning an update is needed each daystatic final intUpdate interval meaning an update is needed each hourstatic final intUpdate interval meaning an update is needed each monthstatic final intUpdate interval meaning an update is never neededstatic final intUpdate interval meaning an update is needed each weekprivate final FileThe (file-)path where the data will be storedprivate final intHow often to update the cached version -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCacheCustomContent(String ident, int updateInterval) Initializes the class. -
Method Summary
Modifier and TypeMethodDescriptionvoidFlushes the data from memory.byte[]getData()Returns the data without performing any updatesReturns the data without performing any updatesprotected booleanThis function serves as a comfort hook to perform additional checks if the cache is validprotected abstract booleanChecks underlying resource is not accessed in offline mode.private voidTries to load the data using the given ident from disk.private booleanprivate voidStores the data to diskprotected abstract byte[]This function will be executed when an update is required.private byte[]Executes an update regardless of updateIntervalExecutes an update regardless of updateIntervalbyte[]Updates data if requiredUpdates data if required
-
Field Details
-
INTERVAL_ALWAYS
Update interval meaning an update is always needed- See Also:
-
INTERVAL_HOURLY
Update interval meaning an update is needed each hour -
INTERVAL_DAILY
Update interval meaning an update is needed each day -
INTERVAL_WEEKLY
Update interval meaning an update is needed each week -
INTERVAL_MONTHLY
Update interval meaning an update is needed each month -
INTERVAL_NEVER
Update interval meaning an update is never needed- See Also:
-
data
Where the data will be stored -
ident
The ident that identifies the stored file. Includes file-ending. -
path
The (file-)path where the data will be stored -
updateInterval
How often to update the cached version
-
-
Constructor Details
-
CacheCustomContent
Initializes the class. Note that all read data will be stored in memory until it is flushed by flushData().- Parameters:
ident- ident that identifies the stored file. Includes file-ending.updateInterval- update interval in seconds. -1 means always
-
-
Method Details
-
updateData
This function will be executed when an update is required. It has to be implemented by the inheriting class and should use a worker if it has a long wall time as the function is executed in the current thread. -
isCacheValid
This function serves as a comfort hook to perform additional checks if the cache is valid- Returns:
- True if the cached copy is still valid
-
needsUpdate
-
isOffline
Checks underlying resource is not accessed in offline mode.- Returns:
- whether resource is accessed in offline mode
-
updateIfRequired
Updates data if required- Returns:
- Returns the data
- Throws:
T- if an error occurs
-
updateIfRequiredString
Updates data if required- Returns:
- Returns the data as string
- Throws:
T- if an error occurs
-
updateForce
Executes an update regardless of updateInterval- Returns:
- Returns the data
- Throws:
T- if an error occurs
-
updateForceString
Executes an update regardless of updateInterval- Returns:
- Returns the data as String
- Throws:
T- if an error occurs
-
getData
Returns the data without performing any updates- Returns:
- the data
- Throws:
T- if an error occurs
-
getDataString
Returns the data without performing any updates- Returns:
- the data as String
- Throws:
T- if an error occurs
-
loadFromDisk
Tries to load the data using the given ident from disk. If this fails, data will be updated, unless run in offline mode -
saveToDisk
Stores the data to disk -
flushData
Flushes the data from memory. Class automatically reloads it from disk or updateData() if required
-