Skip to content

Commit 4cd9314

Browse files
committedJun 23, 2024
fix cache
1 parent 8a9f4d6 commit 4cd9314

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎examples/lru.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
use algorithm::LruCache;
33

4+
#[cfg(feature="ttl")]
45
fn run_ttl() {
56
let mut lru = LruCache::new(3);
67
lru.insert_with_ttl("help", "ok", 1);
@@ -20,5 +21,6 @@ fn main() {
2021
assert_eq!(lru.get("this"), Some(&"lru"));
2122
assert_eq!(lru.get("now"), None);
2223

24+
#[cfg(feature="ttl")]
2325
run_ttl();
2426
}

‎src/cache/lru.rs

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl<K, V, S> LruCache<K, V, S> {
165165
}
166166

167167
/// 获取当前检查lru的间隔
168+
#[cfg(feature="ttl")]
168169
pub fn get_check_step(&self) -> u64 {
169170
self.check_step
170171
}
@@ -174,6 +175,7 @@ impl<K, V, S> LruCache<K, V, S> {
174175
/// 如果数据太大的话遍历一次可能会比较久的时长
175176
/// 一次清理时间复杂度O(n)
176177
/// 仅仅在插入时触发检查,获取时仅检查当前元素
178+
#[cfg(feature="ttl")]
177179
pub fn set_check_step(&mut self, check_step: u64) {
178180
self.check_step = check_step;
179181
self.check_next = get_timestamp() + self.check_step;
@@ -642,6 +644,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {
642644
/// 插入带有生存时间的元素
643645
/// 每次获取像redis一样,并不会更新生存时间
644646
/// 如果需要更新则需要手动的进行重新设置
647+
#[cfg(feature="ttl")]
645648
#[inline(always)]
646649
pub fn insert_with_ttl(&mut self, k: K, v: V, ttl: u64) -> Option<V> {
647650
self.has_ttl = true;

0 commit comments

Comments
 (0)