Class SessionCache

java.lang.Object
de.craftsblock.craftscore.cache.Cache<String,Session>
de.craftsblock.craftsnet.api.session.SessionCache

public class SessionCache extends de.craftsblock.craftscore.cache.Cache<String,Session>
A specialized cache for managing Session objects, allowing efficient storage and retrieval of session instances using unique string keys. The cache has a fixed capacity and employs an underlying caching mechanism to manage its entries.
Since:
3.3.0-SNAPSHOT
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SessionCache(int capacity)
    Constructs a new SessionCache with a specified maximum capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves a Session from the cache by its key.

    Methods inherited from class de.craftsblock.craftscore.cache.Cache

    clear, containsKey, entrySet, get, keySet, moveToFront, put, remove, size, toString, values

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SessionCache

      public SessionCache(int capacity)
      Constructs a new SessionCache with a specified maximum capacity.

      The capacity defines the maximum number of sessions that can be held in the cache. When the capacity is exceeded, the cache evicts the least recently used entry.

      Parameters:
      capacity - the maximum number of sessions the cache can hold.
  • Method Details

    • getOrNew

      public Session getOrNew(String key)
      Retrieves a Session from the cache by its key. If the key does not exist in the cache, a new instance of Session is created and returned.

      This method ensures that a session is always returned, either from the cache or as a new instance. The new session is not automatically added to the cache.

      Parameters:
      key - The unique identifier for the session to retrieve.
      Returns:
      The cached Session associated with the key, or a new Session instance if the key is not present in the cache.