ICache.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /** Copyright 2009 by primeton Corporation.
  2. *
  3. * All rights reserved.
  4. *
  5. * This software is the confidential and proprietary information of
  6. * primeton Corporation ('Confidential Information'). You
  7. * shall not disclose such Confidential Information and shall use
  8. * it only in accordance with the terms of the license agreement
  9. * you entered into with primeton.
  10. */
  11. package com.primeton.dgs.kernel.core.cache;
  12. import javax.validation.constraints.NotNull;
  13. import java.io.Closeable;
  14. /**
  15. * @author xiongbin
  16. *
  17. * @author zhaopx Modify:2019/09/29 修改为支持泛型,废弃 replace, 增加 remove,size 方法
  18. * @Version 2012-8-28
  19. */
  20. public interface ICache<T> extends Closeable {
  21. /**
  22. * 将数据保存至缓存中
  23. * @param key
  24. * @param value
  25. * @throws Exception
  26. */
  27. void add(@NotNull String key, @NotNull T value);
  28. /**
  29. * 将数据保存至缓存中, 过期时间为 exp。 过期单位为:s(秒)
  30. * @param key
  31. * @param exp
  32. * @param value
  33. * @throws Exception
  34. */
  35. void add(@NotNull String key, int exp, @NotNull T value);
  36. /**
  37. * 替换缓存中的数据
  38. *
  39. * 请使用 ${@link #add(String, Object)}
  40. * @param key
  41. * @param value
  42. * @throws Exception
  43. */
  44. @Deprecated
  45. void replace(@NotNull String key, @NotNull T value);
  46. /**
  47. * 请使用 ${@link #add(String, int, Object)}
  48. * @param key
  49. * @param exp
  50. * @param value
  51. * @throws Exception
  52. */
  53. @Deprecated
  54. void replace(@NotNull String key, int exp, @NotNull T value);
  55. /**
  56. * 获取缓存中的数据
  57. * @param key
  58. * @return
  59. * @throws Exception
  60. */
  61. T get(@NotNull String key);
  62. /**
  63. * 移除 某条缓存,不论过期时间
  64. * @param key 缓存的 KEY
  65. * @return
  66. */
  67. T remove(@NotNull String key);
  68. /**
  69. * 移除 指定前缀的缓存
  70. * @param prefix 缓存的 KEY 前缀,相当于在该前缀自动加 *
  71. * @return 返回了移除多少条
  72. */
  73. int removeByPrefix(@NotNull String prefix);
  74. /**
  75. * 清空缓存
  76. * @throws Exception
  77. */
  78. void clear();
  79. /**
  80. *
  81. * add @author zhaopx at: 2019-08-20 17:00
  82. *
  83. * 获得缓存队列的长度
  84. * @return 返回大于等于 0 则代表真实长度,返回 -1 代表无法获得
  85. */
  86. int size();
  87. }