/** Copyright 2009 by primeton Corporation. * * All rights reserved. * * This software is the confidential and proprietary information of * primeton Corporation ('Confidential Information'). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with primeton. */ package com.primeton.dgs.kernel.core.cache; import javax.validation.constraints.NotNull; import java.io.Closeable; /** * @author xiongbin * * @author zhaopx Modify:2019/09/29 修改为支持泛型,废弃 replace, 增加 remove,size 方法 * @Version 2012-8-28 */ public interface ICache extends Closeable { /** * 将数据保存至缓存中 * @param key * @param value * @throws Exception */ void add(@NotNull String key, @NotNull T value); /** * 将数据保存至缓存中, 过期时间为 exp。 过期单位为:s(秒) * @param key * @param exp * @param value * @throws Exception */ void add(@NotNull String key, int exp, @NotNull T value); /** * 替换缓存中的数据 * * 请使用 ${@link #add(String, Object)} * @param key * @param value * @throws Exception */ @Deprecated void replace(@NotNull String key, @NotNull T value); /** * 请使用 ${@link #add(String, int, Object)} * @param key * @param exp * @param value * @throws Exception */ @Deprecated void replace(@NotNull String key, int exp, @NotNull T value); /** * 获取缓存中的数据 * @param key * @return * @throws Exception */ T get(@NotNull String key); /** * 移除 某条缓存,不论过期时间 * @param key 缓存的 KEY * @return */ T remove(@NotNull String key); /** * 移除 指定前缀的缓存 * @param prefix 缓存的 KEY 前缀,相当于在该前缀自动加 * * @return 返回了移除多少条 */ int removeByPrefix(@NotNull String prefix); /** * 清空缓存 * @throws Exception */ void clear(); /** * * add @author zhaopx at: 2019-08-20 17:00 * * 获得缓存队列的长度 * @return 返回大于等于 0 则代表真实长度,返回 -1 代表无法获得 */ int size(); }