Skip to content

Value not expired in VTTLCache #48

@hermeschen1116

Description

@hermeschen1116

I tried the test program below with VTTLCache and found it never expire a value. I'm using cachebox 5.2.2 with Python 3.13

# debug_vttl.py

from __future__ import annotations

import time

from cachebox import Frozen, VTTLCache


def test_raw():
	print("=== raw VTTLCache ===")
	cache = VTTLCache(10, ttl=5)
	cache.insert("ch1", "card-xxx")
	print("t=0s:", cache.get("ch1"), "len:", len(cache))

	time.sleep(6)

	print("t=6s:", cache.get("ch1"), "len:", len(cache))


def test_with_frozen():
	print("=== VTTLCache + Frozen snapshot ===")
	raw = VTTLCache(10, ttl=5)
	raw.insert("ch1", "card-xxx")

	frozen = Frozen(raw)
	print("t=0s:", dict(frozen), "len raw:", len(raw))

	time.sleep(6)

	# 再看一次 live 狀態
	print("t=6s:", dict(frozen), "len raw:", len(raw))


if __name__ == "__main__":
	test_raw()
	test_with_frozen()

The result is

=== raw VTTLCache ===
t=0s: card-xxx len: 1
t=6s: card-xxx len: 1
=== VTTLCache + Frozen snapshot ===
t=0s: {'ch1': 'card-xxx'} len raw: 1
t=6s: {'ch1': 'card-xxx'} len raw: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions