Package org.javacord.core.util.cache
Class MessageCacheImpl
- java.lang.Object
-
- org.javacord.core.util.cache.MessageCacheImpl
-
- All Implemented Interfaces:
MessageCache
,Cleanupable
public class MessageCacheImpl extends Object implements MessageCache, Cleanupable
The implementation ofMessageCache
.
-
-
Constructor Summary
Constructors Constructor Description MessageCacheImpl(DiscordApi api, int capacity, int storageTimeInSeconds, boolean automaticCleanupEnabled)
Creates a new message cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCacheForeverMessage(Message message)
Adds a message to be cached forever.void
addMessage(Message message)
Adds a message to the cache.void
clean()
Cleans the cache.void
cleanup()
Does any cleanup that would prevent this instance from being eligible for garbage collection like cancelling scheduled repeated tasks or callingcleanup
on "owned" cleanupable objects.int
getCapacity()
int
getStorageTimeInSeconds()
void
removeCacheForeverMessage(Message message)
Removes a message to be cached forever.void
removeMessage(Message message)
Removes a message from the cache.void
setAutomaticCleanupEnabled(boolean automaticCleanupEnabled)
void
setCapacity(int capacity)
void
setStorageTimeInSeconds(int storageTimeInSeconds)
-
-
-
Constructor Detail
-
MessageCacheImpl
public MessageCacheImpl(DiscordApi api, int capacity, int storageTimeInSeconds, boolean automaticCleanupEnabled)
Creates a new message cache.- Parameters:
api
- The discord api instance.capacity
- The capacity of the cache, not including messages which are cached forever.storageTimeInSeconds
- The storage time in seconds.automaticCleanupEnabled
- Whether automatic message cache cleanup is enabled.
-
-
Method Detail
-
addMessage
public void addMessage(Message message)
Adds a message to the cache.- Parameters:
message
- The message to add.
-
addCacheForeverMessage
public void addCacheForeverMessage(Message message)
Adds a message to be cached forever.- Parameters:
message
- The message to add.
-
removeCacheForeverMessage
public void removeCacheForeverMessage(Message message)
Removes a message to be cached forever.- Parameters:
message
- The message to remove.
-
removeMessage
public void removeMessage(Message message)
Removes a message from the cache.- Parameters:
message
- The message to remove.
-
clean
public void clean()
Cleans the cache.
-
getCapacity
public int getCapacity()
- Specified by:
getCapacity
in interfaceMessageCache
-
setCapacity
public void setCapacity(int capacity)
- Specified by:
setCapacity
in interfaceMessageCache
-
getStorageTimeInSeconds
public int getStorageTimeInSeconds()
- Specified by:
getStorageTimeInSeconds
in interfaceMessageCache
-
setStorageTimeInSeconds
public void setStorageTimeInSeconds(int storageTimeInSeconds)
- Specified by:
setStorageTimeInSeconds
in interfaceMessageCache
-
setAutomaticCleanupEnabled
public void setAutomaticCleanupEnabled(boolean automaticCleanupEnabled)
- Specified by:
setAutomaticCleanupEnabled
in interfaceMessageCache
-
cleanup
public void cleanup()
Description copied from interface:Cleanupable
Does any cleanup that would prevent this instance from being eligible for garbage collection like cancelling scheduled repeated tasks or callingcleanup
on "owned" cleanupable objects. This method has to be thread-safe and idempotent.- Specified by:
cleanup
in interfaceCleanupable
-
-