Skip to content

[bug] cache#keys return the expired and not exists keys. #40

@zw963

Description

@zw963

Hi, I want to use cache shard to count how many people are online on my website.

When user visit my website, will poll peridly to report he is still online.

I want to use Cache::MemoryStore to create items, but expired in 2 minutes.

Then, I can use cache.keys.size to get the current alive users count.

But, It's seem like cache.keys not work as expected.

please check following example code:

require "./src/cache"

cache = Cache::MemoryStore(String, String).new(expires_in: 2.seconds)

cache.fetch("foo") { "foo" }
cache.fetch("bar", expires_in: 5.seconds) { "bar" }

p! cache.keys # Set{"foo", "bar"}, it correct.

sleep 3.seconds

p! cache.exists?("foo") # false
p! cache.exists?("bar") # true

p! cache.keys # => Set{"foo", "bar"}, foo is expired, and not exists?, it should be Set{"bar"}, right?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions