提交 f3518e2f 编写于 作者: J JessYan

Improve Cache's comment

上级 dd3df902
......@@ -43,7 +43,7 @@ public interface Cache<K, V> {
* Returns a new cache
*
* @param type 框架中需要缓存的模块类型
* @return
* @return {@link Cache}
*/
@NonNull
Cache build(CacheType type);
......@@ -52,22 +52,22 @@ public interface Cache<K, V> {
/**
* 返回当前缓存已占用的总 size
*
* @return
* @return {@code size}
*/
int size();
/**
* 返回当前缓存所能允许的最大 size
*
* @return
* @return {@code maxSize}
*/
int getMaxSize();
/**
* 返回这个 {@code key} 在缓存中对应的 {@code value}, 如果返回 {@code null} 说明这个 {@code key} 没有对应的 {@code value}
*
* @param key
* @return
* @param key {@code key}
* @return {@code value}
*/
@Nullable
V get(K key);
......@@ -76,9 +76,9 @@ public interface Cache<K, V> {
* 将 {@code key} 和 {@code value} 以条目的形式加入缓存,如果这个 {@code key} 在缓存中已经有对应的 {@code value}
* 则此 {@code value} 被新的 {@code value} 替换并返回,如果为 {@code null} 说明是一个新条目
*
* @param key
* @param value
* @return
* @param key {@code key}
* @param value {@code value}
* @return 如果这个 {@code key} 在容器中已经储存有 {@code value}, 则返回之前的 {@code value} 否则返回 {@code null}
*/
@Nullable
V put(K key, V value);
......@@ -87,8 +87,8 @@ public interface Cache<K, V> {
* 移除缓存中这个 {@code key} 所对应的条目,并返回所移除条目的 value
* 如果返回为 {@code null} 则有可能时因为这个 {@code key} 对应的 value 为 {@code null} 或条目不存在
*
* @param key
* @return
* @param key {@code key}
* @return 如果这个 {@code key} 在容器中已经储存有 {@code value} 并且删除成功则返回删除的 {@code value}, 否则返回 {@code null}
*/
@Nullable
V remove(K key);
......@@ -96,15 +96,15 @@ public interface Cache<K, V> {
/**
* 如果这个 {@code key} 在缓存中有对应的 value 并且不为 {@code null}, 则返回 {@code true}
*
* @param key
* @return
* @param key {@code key}
* @return {@code true} 为在容器中含有这个 {@code key}, 否则为 {@code false}
*/
boolean containsKey(K key);
/**
* 返回当前缓存中含有的所有 {@code key}
*
* @return
* @return {@code keySet}
*/
Set<K> keySet();
......
/*
* Copyright 2017 JessYan
* Copyright 2018 JessYan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -68,7 +68,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
}
/**
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
*
* @param key {@code key}
* @return {@code value}
......@@ -83,7 +83,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
}
/**
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
*
* @param key {@code key}
* @param value {@code value}
......@@ -99,10 +99,10 @@ public class IntelligentCache<V> implements Cache<String, V> {
}
/**
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
*
* @param key {@code key}
* @return 如果 {@code key} 在容器中有 {@code value} 并且删除成功则返回删除的 {@code value}, 否则返回 {@code null}
* @return 如果这个 {@code key} 在容器中已经储存有 {@code value} 并且删除成功则返回删除的 {@code value}, 否则返回 {@code null}
*/
@Nullable
@Override
......@@ -114,7 +114,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
}
/**
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
* 如果在 {@code key} 中使用 {@link #KEY_KEEP} 作为前缀, 则操作 {@link #mMap}, 否则操作 {@link #mCache}
*
* @param key {@code key}
* @return {@code true} 为在容器中含有这个 {@code key}, 否则为 {@code false}
......@@ -128,9 +128,9 @@ public class IntelligentCache<V> implements Cache<String, V> {
}
/**
* 将 {@link #mMap} 和 {@link #mCache} 的 keySet 合并返回
* 将 {@link #mMap} 和 {@link #mCache} 的 {@code keySet} 合并返回
*
* @return 合并后的 keySet
* @return 合并后的 {@code keySet}
*/
@Override
public Set<String> keySet() {
......
......@@ -72,6 +72,7 @@ public class LruCache<K, V> implements Cache<K, V> {
* 子类可以重写这个方法以适应不同的单位,比如说 bytes
*
* @param item 每个 {@code item} 所占用的 size
* @return 单个 item 的 {@code size}
*/
protected int getItemSize(V item) {
return 1;
......@@ -89,6 +90,8 @@ public class LruCache<K, V> implements Cache<K, V> {
/**
* 返回当前缓存所能允许的最大 size
*
* @return {@code maxSize}
*/
@Override
public synchronized int getMaxSize() {
......@@ -97,6 +100,8 @@ public class LruCache<K, V> implements Cache<K, V> {
/**
* 返回当前缓存已占用的总 size
*
* @return {@code size}
*/
@Override
public synchronized int size() {
......@@ -107,6 +112,7 @@ public class LruCache<K, V> implements Cache<K, V> {
* 如果这个 {@code key} 在缓存中有对应的 {@code value} 并且不为 {@code null},则返回 true
*
* @param key 用来映射的 {@code key}
* @return {@code true} 为在容器中含有这个 {@code key}, 否则为 {@code false}
*/
@Override
public synchronized boolean containsKey(K key) {
......@@ -116,7 +122,7 @@ public class LruCache<K, V> implements Cache<K, V> {
/**
* 返回当前缓存中含有的所有 {@code key}
*
* @return
* @return {@code keySet}
*/
@Override
public Set<K> keySet() {
......@@ -127,6 +133,7 @@ public class LruCache<K, V> implements Cache<K, V> {
* 返回这个 {@code key} 在缓存中对应的 {@code value}, 如果返回 {@code null} 说明这个 {@code key} 没有对应的 {@code value}
*
* @param key 用来映射的 {@code key}
* @return {@code value}
*/
@Override
@Nullable
......@@ -143,6 +150,7 @@ public class LruCache<K, V> implements Cache<K, V> {
*
* @param key 通过这个 {@code key} 添加条目
* @param value 需要添加的 {@code value}
* @return 如果这个 {@code key} 在容器中已经储存有 {@code value}, 则返回之前的 {@code value} 否则返回 {@code null}
*/
@Override
@Nullable
......@@ -170,6 +178,7 @@ public class LruCache<K, V> implements Cache<K, V> {
* 如果返回为 {@code null} 则有可能时因为这个 {@code key} 对应的 {@code value} 为 {@code null} 或条目不存在
*
* @param key 使用这个 {@code key} 移除对应的条目
* @return 如果这个 {@code key} 在容器中已经储存有 {@code value} 并且删除成功则返回删除的 {@code value}, 否则返回 {@code null}
*/
@Override
@Nullable
......@@ -192,7 +201,7 @@ public class LruCache<K, V> implements Cache<K, V> {
/**
* 当指定的 size 小于当前缓存已占用的总 size 时,会开始清除缓存中最近最少使用的条目
*
* @param size
* @param size {@code size}
*/
protected synchronized void trimToSize(int size) {
Map.Entry<K, V> last;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册