public class ServerCache
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.CharSequence |
DEFAULT_ENTRY_LOCALHOST
The default entry for the "localhost" server.
|
private java.util.Map<java.lang.String,Info> |
entries
The cached entries.
|
private java.io.File |
file
The backing file.
|
Constructor and Description |
---|
ServerCache(java.io.File file)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
addEntry(java.lang.CharSequence metaserverEntryLine,
long timestamp)
Parses a metaserver entry line and adds the result to
entries . |
void |
expire(long timestamp)
Expires entries older than a given timestamp from the cache.
|
java.util.Map<java.lang.String,MetaserverEntry> |
getAll()
Returns all cached entries.
|
private void |
load()
Loads the entries from the backing file.
|
static java.lang.String |
makeKey(MetaserverEntry metaserverEntry)
Returns the key for a metaserver entry.
|
void |
put(MetaserverEntry metaserverEntry)
Adds an entry to the cache.
|
void |
save()
Saves all entries to the backing file.
|
private void |
saveInternal(java.io.File file)
Saves all entries to the backing file.
|
@NotNull public static final java.lang.CharSequence DEFAULT_ENTRY_LOCALHOST
@NotNull private final java.util.Map<java.lang.String,Info> entries
makeKey(MetaserverEntry)
) to
Info
instance for the metaserver entry.@Nullable private final java.io.File file
public ServerCache(@Nullable java.io.File file)
file
- the backing file or null
to not cache on diskprivate boolean addEntry(@NotNull java.lang.CharSequence metaserverEntryLine, long timestamp)
entries
.metaserverEntryLine
- the metaserver entry line to parsetimestamp
- the query timestamppublic void expire(long timestamp)
timestamp
- the timestamp@NotNull public java.util.Map<java.lang.String,MetaserverEntry> getAll()
private void load()
@NotNull public static java.lang.String makeKey(@NotNull MetaserverEntry metaserverEntry)
metaserverEntry
- the metaserver entrypublic void put(@NotNull MetaserverEntry metaserverEntry)
metaserverEntry
- the entry to addpublic void save()
private void saveInternal(@NotNull java.io.File file) throws java.io.IOException
file
- the file to writejava.io.IOException
- if an I/O error occurs