🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
获取缓存对象 ~~~ //获取缓存对象 ICache cache = getCacheManager().getICache("XX_CACHE_NAME"); /** * 从spring上下文中获取缓存管理器 * * @return */ public ICacheManager getCacheManager() { String springCacheManager = SpringPropertyHolder.getContextProperty("cacheManagerName", "springCacheManager"); return SpringContextHolder.getBean(springCacheManager, ICacheManager.class); } ~~~ 或者直接 ``` ICache cache = CacheManager.getCacheManager().getICache("XX_CACHE_NAME"); ``` 接口方法定义 ~~~ //缓存接口继承自spring public interface ICache extends org.springframework.cache.Cache { /** * 置入缓存 * * @param key * @param value */ void put(Object key, Object value); /** * get方法返回的是个ValueWrapper类型对象,该方法转换成值 * * @param key * @return */ <T> T getValue(Object key); /** * 设置过期时间。-1表示永不过期,0表示立即失效 * * @param key:键值 * @param expire:存活时间。单位秒 */ void expire(Object key, long expireSeconds); /** * 移除key值 * * @param key the key whose mapping is to be removed from the cache */ void evict(Object key); /** * 清空缓存 * */ void clear(); /** * 返回key的剩余存活时间,单位毫秒 */ Long ttl(Object key); /** * 获取所有key */ Iterator<Object> keys(); /** * 获取大小 */ Long size(); /** * 获取缓存名称. */ String getName(); /** * 获取缓存内部对象 */ Object getNativeCache(); /** * 获取缓存管理器 * * @return */ CacheManager getCacheManager(); } ~~~