Class SimpleCache<V>

java.lang.Object
com.google.genkit.core.middleware.SimpleCache<V>
Type Parameters:
V - the value type
All Implemented Interfaces:
MiddlewareCache<V>

public class SimpleCache<V> extends Object implements MiddlewareCache<V>
SimpleCache is a thread-safe in-memory cache implementation for use with caching middleware.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a SimpleCache with no TTL (entries never expire).
    SimpleCache(long ttlMs)
    Creates a SimpleCache with the specified TTL.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all values from the cache.
    get(String key)
    Gets a value from the cache.
    void
    put(String key, V value)
    Puts a value in the cache.
    void
    Removes a value from the cache.
    int
    Returns the number of entries in the cache.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SimpleCache

      public SimpleCache()
      Creates a SimpleCache with no TTL (entries never expire).
    • SimpleCache

      public SimpleCache(long ttlMs)
      Creates a SimpleCache with the specified TTL.
      Parameters:
      ttlMs - time-to-live in milliseconds (0 for no expiration)
  • Method Details

    • get

      public V get(String key)
      Description copied from interface: MiddlewareCache
      Gets a value from the cache.
      Specified by:
      get in interface MiddlewareCache<V>
      Parameters:
      key - the cache key
      Returns:
      the cached value, or null if not found
    • put

      public void put(String key, V value)
      Description copied from interface: MiddlewareCache
      Puts a value in the cache.
      Specified by:
      put in interface MiddlewareCache<V>
      Parameters:
      key - the cache key
      value - the value to cache
    • remove

      public void remove(String key)
      Description copied from interface: MiddlewareCache
      Removes a value from the cache.
      Specified by:
      remove in interface MiddlewareCache<V>
      Parameters:
      key - the cache key
    • clear

      public void clear()
      Description copied from interface: MiddlewareCache
      Clears all values from the cache.
      Specified by:
      clear in interface MiddlewareCache<V>
    • size

      public int size()
      Returns the number of entries in the cache.
      Returns:
      the cache size