Interface CacheWriter<K,V>

Type Parameters:
K - the most general type of keys this writer can write; for example Object if any key is acceptable
V - the most general type of values this write can write; for example Object if any value is acceptable
All Known Implementing Classes:
Caffeine.CacheWriterAdapter, DisabledWriter

@Deprecated public interface CacheWriter<K,V>
Deprecated.
Scheduled for removal in version 3.0.0. Consider instead using Map compute methods for extending manual write and remove operations, and using Caffeine.evictionListener(RemovalListener) for extending removals due to eviction.
Communicates the write or deletion of a value, based on a key, to an external resource. A writer is notified by the cache each time an entry is explicitly created or modified, or removed for any reason. The writer is not notified when an entry is loaded or computed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(@NonNull K key, @Nullable V value, @NonNull RemovalCause cause)
    Deprecated.
    Deletes the value corresponding to the key from the external resource.
    static <K, V> @NonNull CacheWriter<K,V>
    Deprecated.
    Returns a writer that does nothing.
    void
    write(@NonNull K key, @NonNull V value)
    Deprecated.
    Writes the value corresponding to the key to the external resource.
  • Method Details

    • write

      void write(@NonNull K key, @NonNull V value)
      Deprecated.
      Writes the value corresponding to the key to the external resource. The cache will communicate a write when an entry in the cache is created or modified, except when that was due to a load or computation.
      Parameters:
      key - the non-null key whose value should be written
      value - the value associated with key that should be written
      Throws:
      RuntimeException - or Error, in which case the mapping is unchanged
    • delete

      void delete(@NonNull K key, @Nullable V value, @NonNull RemovalCause cause)
      Deprecated.
      Deletes the value corresponding to the key from the external resource. The cache will communicate a delete when the entry is explicitly removed or evicted.
      Parameters:
      key - the non-null key whose value was removed
      value - the value associated with key, or null if collected
      cause - the reason for which the entry was removed
      Throws:
      RuntimeException - or Error, in which case the mapping is unchanged
    • disabledWriter

      static <K, V> @NonNull CacheWriter<K,V> disabledWriter()
      Deprecated.
      Returns a writer that does nothing.
      Type Parameters:
      K - the type of keys
      V - the type of values
      Returns:
      a writer that performs no operations