Class SpringReplayCache

java.lang.Object
org.springframework.ws.soap.security.wss4j2.cache.SpringReplayCache
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.wss4j.common.cache.ReplayCache
Direct Known Subclasses:
ConcurrentMapReplayCache

public class SpringReplayCache extends Object implements org.apache.wss4j.common.cache.ReplayCache
Apache WSS4J ReplayCache backed by a Spring Cache. Each key stores an expiry Instant with configurable TTLs. The default TTL is 5 minutes and the max TTL is an hour.

contains(String) consults that instant and evicts the entry when it is past expiry. This does not rely on the backing cache's own TTL configuration.

Subclasses may override onCacheAccess() and to perform additional eviction, for example, a full sweep over an in-memory cache.

For multi hosts deployment in production, make sure to use a Cache implementation that is distributed, as each host needs to access the same data. For simple, single host deployment, ConcurrentMapReplayCache can be used.

Since:
3.1.9
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Default TTL for entries in seconds.
    static final long
    Maximum TTL for entries in seconds.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpringReplayCache(org.springframework.cache.Cache cache)
    Create an instance with the given cache and default TTLs.
    SpringReplayCache(org.springframework.cache.Cache cache, long defaultTtlSeconds, long maxTtlSeconds)
    Create an instance with the given cache and TTLs.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String identifier)
     
    void
    add(String identifier, @Nullable Instant expiry)
     
    void
     
    boolean
    contains(String identifier)
     
    protected final org.springframework.cache.Cache
     
    protected void
    Invoked when the cache is accessed, either after an entry has been stored or before checking for the presence of one.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_TTL

      public static final long DEFAULT_TTL
      Default TTL for entries in seconds.
      See Also:
    • MAX_TTL

      public static final long MAX_TTL
      Maximum TTL for entries in seconds.
      See Also:
  • Constructor Details

    • SpringReplayCache

      public SpringReplayCache(org.springframework.cache.Cache cache)
      Create an instance with the given cache and default TTLs.
      Parameters:
      cache - the cache to use
    • SpringReplayCache

      public SpringReplayCache(org.springframework.cache.Cache cache, long defaultTtlSeconds, long maxTtlSeconds)
      Create an instance with the given cache and TTLs.
      Parameters:
      cache - the cache to use
      defaultTtlSeconds - the default TTL in seconds
      maxTtlSeconds - the maximum TTL in seconds
  • Method Details

    • getCache

      protected final org.springframework.cache.Cache getCache()
    • add

      public void add(String identifier)
      Specified by:
      add in interface org.apache.wss4j.common.cache.ReplayCache
    • add

      public void add(String identifier, @Nullable Instant expiry)
      Specified by:
      add in interface org.apache.wss4j.common.cache.ReplayCache
    • contains

      public boolean contains(String identifier)
      Specified by:
      contains in interface org.apache.wss4j.common.cache.ReplayCache
    • onCacheAccess

      protected void onCacheAccess()
      Invoked when the cache is accessed, either after an entry has been stored or before checking for the presence of one.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable