com.h3c.util.cache

## Class CacheModelProxy<K,V>

- java.lang.Object
- - com.h3c.util.cache.CacheModelProxy<K,V>

- Type Parameters:
    `K` - type of the key to identify a cached value. It should be an immutable type. It is critical this type implements equals() and hashCode() correctly.
    `V` - type of the cached value.
  All Implemented Interfaces:
    Cache<K,V>

      public class CacheModelProxy<K,V>
      extends Object
      implements Cache<K,V>

  Proxy that integrates the cache to the model. The proxy gets values from the cache and it delegates to the model in case the value is not contained in the cache.

  There is no need to call `Cache.put(Object, Object)` in CacheModelProxy because the cache will be automatically updated by the model when an object that doesn't belong to the cache is requested. If `Cache.get(Object)` in CacheModelProxy returns `null` it means the object does not belong to the cache nor the model.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `CacheModelProxy.Model<K,V>` Model.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CacheModelProxy(Cache<K,V> cache, CacheModelProxy.Model<K,V> model)` Creates a new `Cache`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears the cache.
    `V` | `get(K key)` Gets a value from the cache.
    `void` | `invalidate(K key)` Invalidates a key.
    `void` | `put(K key, V value)` Puts a value into the cache.

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### CacheModelProxy

          public CacheModelProxy(Cache<K,V> cache,
                         CacheModelProxy.Model<K,V> model)

      Creates a new `Cache`.
      Parameters:
        `cache` - cache delegate.
        `model` - model.

  - ### Method Detail

    - #### put

          public void put(K key,
                 V value)

      Description copied from interface: `Cache`
      Puts a value into the cache.
      Specified by:
        `put` in interface `Cache<K,V>`
      Parameters:
        `key` - key.
        `value` - value.

    - #### get

          public V get(K key)

      Description copied from interface: `Cache`
      Gets a value from the cache.
      Specified by:
        `get` in interface `Cache<K,V>`
      Parameters:
        `key` - value's key.
      Returns:
        the value associated to the given key if it exists in the cache, `null` otherwise.

    - #### invalidate

          public void invalidate(K key)

      Description copied from interface: `Cache`
      Invalidates a key. This will cause the key to be removed from the cache. This method should be called when the object associated to the given key is no longer valid (A new copy should be retrieved from the model in the next read or the object no longer exists in the model). Deletion of entries from the cache due space management should be handled by the cache's implementation.
      Specified by:
        `invalidate` in interface `Cache<K,V>`
      Parameters:
        `key` - key to invalidate.

    - #### clear

          public void clear()

      Description copied from interface: `Cache`
      Clears the cache.
      Specified by:
        `clear` in interface `Cache<K,V>`

Copyright © 2014. All Rights Reserved.