com.seeyon.ctp.common.cache
接口 CacheMap<K extends java.io.Serializable,V extends java.io.Serializable>

类型参数:
K -
V -
所有超级接口:
GroupCacheable

public interface CacheMap<K extends java.io.Serializable,V extends java.io.Serializable>
extends GroupCacheable

Map缓存,暂存名/值对,机制与Map相同。
注意:
当缓存的值改变时,必须重新调用put更新或调用notifyUpdate通知缓存组件。
比如缓存的值为java collection,调用get取值后直接对collection操作,缓存不能监听值的变化。

作者:
wangwy

方法摘要
 boolean contains(K key)
          判断是否存在指定的缓存项。
 V get(K key)
          取得指定的缓存项。
 DataLoader<K> getDataLoader()
          取得缓存数据加载。
 java.util.Set<K> keySet()
          Returns a set view of the keys contained in this map.
 void notifyUpdate(java.util.Collection<K> keys)
          批量通知缓存项改变,需要更新。
 void notifyUpdate(K key)
          通知缓存项改变,需要更新。
 void notifyUpdate(K[] keys)
          批量通知缓存项改变,需要更新。
 void put(K key, V value)
          设置缓存。
 void putAll(java.util.Map<? extends K,? extends V> map)
          将Map中的所有项目设置到缓存中。
 void reload()
          通过dataloader重新加载整个缓存,如果没有dataloader,不做任何操作。
 void reload(K k)
          通过dataloader加载指定缓存项,如果没有dataloader,不做任何操作。
 V remove(K key)
          移除缓存项。
 boolean removeAll(java.util.Collection<K> keys)
          移除缓存项。
 void replaceAll(java.util.Map<? extends K,? extends V> map)
          清除缓存并将Map中的所有项目设置到缓存中。
 void setDataLoader(DataLoader<K> loader)
          设置缓存数据加载。
 java.util.Map<K,V> toMap()
          将缓存转化为Map表示。
 java.util.Collection<V> values()
          Returns a collection view of the values contained in this map.
 
从接口 com.seeyon.ctp.common.cache.GroupCacheable 继承的方法
clear, getGroup, getName, isEmpty, size
 

方法详细信息

put

void put(K key,
         V value)
设置缓存。如果指定的缓存项已存在则以新值覆盖。

参数:
key -
value -

putAll

void putAll(java.util.Map<? extends K,? extends V> map)
将Map中的所有项目设置到缓存中。效果相当于循环调用put,但性能要高一些。不清除原有项目进行追加,如果Key冲突则覆盖原缓存项。

参数:
map - Java Map

replaceAll

void replaceAll(java.util.Map<? extends K,? extends V> map)
清除缓存并将Map中的所有项目设置到缓存中。效果相当于先clear再putAll。

参数:
map - Java Map

notifyUpdate

void notifyUpdate(K key)
通知缓存项改变,需要更新。

参数:
key - 缓存的Key

notifyUpdate

void notifyUpdate(K[] keys)
批量通知缓存项改变,需要更新。

参数:
keys - 缓存的Key数组

notifyUpdate

void notifyUpdate(java.util.Collection<K> keys)
批量通知缓存项改变,需要更新。

参数:
keys - 缓存的Key集合

get

V get(K key)
取得指定的缓存项。

参数:
key - 缓存的Key
返回:
如果不存在返回null,缓存值为null 时会有歧义,如果需要判断请使用contains方法。

remove

V remove(K key)
移除缓存项。

参数:
key - 缓存的Key
返回:
被移除的缓存项。如果不存在返回null

removeAll

boolean removeAll(java.util.Collection<K> keys)
移除缓存项。

参数:
key - 缓存的Key集合,所有以集合中元素为key的换成都会被移除。
返回:
如果有元素被移除返回true,否则返回false

contains

boolean contains(K key)
判断是否存在指定的缓存项。

参数:
key - 缓存的Key
返回:
存在返回true,否则返回false

toMap

java.util.Map<K,V> toMap()
将缓存转化为Map表示。

返回:
Map,Key为缓存的Key,Value为缓存中的对象。

keySet

java.util.Set<K> keySet()
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

返回:
a set view of the keys contained in this map.

values

java.util.Collection<V> values()
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

返回:
a collection view of the values contained in this map.

setDataLoader

void setDataLoader(DataLoader<K> loader)
设置缓存数据加载。

参数:
loader -

getDataLoader

DataLoader<K> getDataLoader()
取得缓存数据加载。

返回:

reload

void reload()
通过dataloader重新加载整个缓存,如果没有dataloader,不做任何操作。


reload

void reload(K k)
通过dataloader加载指定缓存项,如果没有dataloader,不做任何操作。

参数:
k - 缓存的key