本篇文章給大家分享的是有關(guān)shiro中緩存機(jī)制的原理是什么,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
Shiro提供了類似于Spring的Cache抽象,即Shiro本身不實(shí)現(xiàn)Cache,但是對(duì)Cache進(jìn)行了又抽象,方便更換不同的底層Cache實(shí)現(xiàn)。
Shiro提供的Cache接口:
Java代碼
public interface Cache{ //根據(jù)Key獲取緩存中的值 public V get(K key) throws CacheException; //往緩存中放入key-value,返回緩存中之前的值 public V put(K key, V value) throws CacheException; //移除緩存中key對(duì)應(yīng)的值,返回該值 public V remove(K key) throws CacheException; //清空整個(gè)緩存 public void clear() throws CacheException; //返回緩存大小 public int size(); //獲取緩存中所有的key public Set keys(); //獲取緩存中所有的value public Collection values(); }