Class PostgresCacheAdapter

java.lang.Object
org.fireflyframework.cache.adapter.postgres.PostgresCacheAdapter
All Implemented Interfaces:
org.fireflyframework.cache.core.CacheAdapter

public class PostgresCacheAdapter extends Object implements org.fireflyframework.cache.core.CacheAdapter
PostgreSQL-backed reactive cache adapter implemented over R2DBC.

Cache entries are stored in a single relational table keyed by (cache_name, cache_key). Values are serialized with a CacheSerializer into a JSON String, encoded as UTF-8 bytes and persisted in a BYTEA column. Expiry is enforced both lazily on read (rows whose expires_at is in the past are treated as absent) and at write time (expires_at = NOW() + ttl).

All operations run reactively against a Spring-managed ConnectionFactory; connections are acquired and released per operation via Mono.usingWhen(Publisher, java.util.function.Function, java.util.function.Function).

  • Constructor Details

    • PostgresCacheAdapter

      public PostgresCacheAdapter(String cacheName, io.r2dbc.spi.ConnectionFactory connectionFactory, PostgresCacheConfig config, org.fireflyframework.cache.serialization.CacheSerializer serializer)
  • Method Details

    • get

      public <K,V> reactor.core.publisher.Mono<Optional<V>> get(K key)
      Specified by:
      get in interface org.fireflyframework.cache.core.CacheAdapter
    • get

      public <K,V> reactor.core.publisher.Mono<Optional<V>> get(K key, Class<V> valueType)
      Specified by:
      get in interface org.fireflyframework.cache.core.CacheAdapter
    • put

      public <K,V> reactor.core.publisher.Mono<Void> put(K key, V value)
      Specified by:
      put in interface org.fireflyframework.cache.core.CacheAdapter
    • put

      public <K,V> reactor.core.publisher.Mono<Void> put(K key, V value, Duration ttl)
      Specified by:
      put in interface org.fireflyframework.cache.core.CacheAdapter
    • putIfAbsent

      public <K,V> reactor.core.publisher.Mono<Boolean> putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface org.fireflyframework.cache.core.CacheAdapter
    • putIfAbsent

      public <K,V> reactor.core.publisher.Mono<Boolean> putIfAbsent(K key, V value, Duration ttl)
      Specified by:
      putIfAbsent in interface org.fireflyframework.cache.core.CacheAdapter
    • evict

      public <K> reactor.core.publisher.Mono<Boolean> evict(K key)
      Specified by:
      evict in interface org.fireflyframework.cache.core.CacheAdapter
    • clear

      public reactor.core.publisher.Mono<Void> clear()
      Specified by:
      clear in interface org.fireflyframework.cache.core.CacheAdapter
    • evictByPrefix

      public reactor.core.publisher.Mono<Long> evictByPrefix(String keyPrefixToMatch)
      Specified by:
      evictByPrefix in interface org.fireflyframework.cache.core.CacheAdapter
    • exists

      public <K> reactor.core.publisher.Mono<Boolean> exists(K key)
      Specified by:
      exists in interface org.fireflyframework.cache.core.CacheAdapter
    • keys

      public <K> reactor.core.publisher.Mono<Set<K>> keys()
      Specified by:
      keys in interface org.fireflyframework.cache.core.CacheAdapter
    • size

      public reactor.core.publisher.Mono<Long> size()
      Specified by:
      size in interface org.fireflyframework.cache.core.CacheAdapter
    • getStats

      public reactor.core.publisher.Mono<org.fireflyframework.cache.core.CacheStats> getStats()
      Specified by:
      getStats in interface org.fireflyframework.cache.core.CacheAdapter
    • getCacheType

      public org.fireflyframework.cache.core.CacheType getCacheType()
      Specified by:
      getCacheType in interface org.fireflyframework.cache.core.CacheAdapter
    • getCacheName

      public String getCacheName()
      Specified by:
      getCacheName in interface org.fireflyframework.cache.core.CacheAdapter
    • isAvailable

      public boolean isAvailable()
      Specified by:
      isAvailable in interface org.fireflyframework.cache.core.CacheAdapter
    • getHealth

      public reactor.core.publisher.Mono<org.fireflyframework.cache.core.CacheHealth> getHealth()
      Specified by:
      getHealth in interface org.fireflyframework.cache.core.CacheAdapter
    • close

      public void close()
      Specified by:
      close in interface org.fireflyframework.cache.core.CacheAdapter