hutool.cache.weak_cache

弱引用缓存实现

Module Contents

Classes

WeakCache

弱引用缓存

API

class hutool.cache.weak_cache.WeakCache(capacity: int = 16)

弱引用缓存

使用弱引用存储值,当值没有其他引用时自动清理。 不支持弱引用的类型(int、str 等)会回退到强引用存储。

Initialization

初始化弱引用缓存。

参数:

capacity – 缓存最大容量,默认16

_total_size()
get(key: str, default: object = None) object

获取缓存值

参数:
  • key – 缓存键

  • default – 默认值

返回:

缓存值

put(key: str, value: object) None

设置缓存值

参数:
  • key – 缓存键

  • value – 缓存值

remove(key: str) None

移除缓存

参数:

key – 缓存键

clear() None

清空缓存

size() int

缓存大小

返回:

缓存条目数

is_empty() bool

是否为空

返回:

缓存是否为空

get_hit_count() int

获取命中次数

返回:

命中次数

get_miss_count() int

获取未命中次数

返回:

未命中次数

key_set()

获取所有键

返回:

键列表

__contains__(key: str) bool
__len__() int