Module bus.pager

Class SimpleCache<K,V>

java.lang.Object
org.miaixz.bus.pager.cache.SimpleCache<K,V>
Type Parameters:
K - the type of keys maintained by this cache
V - the type of mapped values
All Implemented Interfaces:
org.miaixz.bus.cache.CacheX<K,V>

public class SimpleCache<K,V> extends Object implements org.miaixz.bus.cache.CacheX<K,V>
Simple MyBatis Cache implementation that wraps an Cache instance. This class allows configuring the underlying MyBatis cache using properties.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleCache(Properties properties)
    Constructs a new SimpleCache with the given properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all entries from the cache.
    read(Collection<K> keys)
    Reads multiple values from the cache associated with the given keys.
    read(K key)
    Reads a value from the cache associated with the given key.
    void
    remove(K... keys)
    Removes the specified keys from the cache.
    void
    write(Map<K,V> map, long expire)
    Writes multiple key-value pairs to the cache with a specified expiration time.
    void
    write(K key, V value, long expire)
    Writes a key-value pair to the cache with a specified expiration time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.cache.CacheX

    containsKey, write
  • Constructor Details

    • SimpleCache

      public SimpleCache(Properties properties)
      Constructs a new SimpleCache with the given properties. The properties are used to configure the underlying MyBatis cache, including its type, eviction policy, and size.
      Parameters:
      properties - the properties for configuring the cache
  • Method Details

    • read

      public V read(K key)
      Reads a value from the cache associated with the given key.
      Specified by:
      read in interface org.miaixz.bus.cache.CacheX<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this cache contains no mapping for the key
    • read

      public Map<K,V> read(Collection<K> keys)
      Reads multiple values from the cache associated with the given keys. This implementation returns an empty map as it's not directly supported by the underlying MyBatis cache.
      Specified by:
      read in interface org.miaixz.bus.cache.CacheX<K,V>
      Parameters:
      keys - a collection of keys for which to retrieve values
      Returns:
      an empty map
    • write

      public void write(K key, V value, long expire)
      Writes a key-value pair to the cache with a specified expiration time. The expiration time is not directly used by the underlying MyBatis cache, which is configured via properties.
      Specified by:
      write in interface org.miaixz.bus.cache.CacheX<K,V>
      Parameters:
      key - the key with which the specified value is to be associated
      value - the value to be associated with the specified key
      expire - the expiration time in milliseconds (not directly used by this implementation)
    • write

      public void write(Map<K,V> map, long expire)
      Writes multiple key-value pairs to the cache with a specified expiration time. This implementation does nothing as it's not directly supported by the underlying MyBatis cache.
      Specified by:
      write in interface org.miaixz.bus.cache.CacheX<K,V>
      Parameters:
      map - a map of key-value pairs to be stored in the cache
      expire - the expiration time in milliseconds (not directly used by this implementation)
    • remove

      public void remove(K... keys)
      Removes the specified keys from the cache. This implementation does nothing as it's not directly supported by the underlying MyBatis cache.
      Specified by:
      remove in interface org.miaixz.bus.cache.CacheX<K,V>
      Parameters:
      keys - an array of keys to be removed from the cache
    • clear

      public void clear()
      Clears all entries from the cache. This implementation does nothing as it's not directly supported by the underlying MyBatis cache.
      Specified by:
      clear in interface org.miaixz.bus.cache.CacheX<K,V>