8000 idleScanTime evicts active elements of Cache · Issue #206 · cache2k/cache2k · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 10000
idleScanTime evicts active elements of Cache #206
Open
@vdshb

Description

@vdshb

I'm trying to understand how idleScanTime works. I've created a test, and can't realize why it fails. It looks like a bug to me.

public class Test {
    public static void main(String[] args) throws InterruptedException {
        // GIVEN
        var cache = new Cache2kBuilder<Integer, String>() {}
                .idleScanTime(Duration.of(500, ChronoUnit.MILLIS))
                .build();

        // WHEN
        cache.put(1, "1");

        // THEN
        for (int i = 0; i < 60; i++) {
            Thread.sleep(30);
            if (!"1".equals(cache.get(1))) {
                // This exception is thrown on i=33
                throw new RuntimeException(
                    "Cache supposed to have the value as last access was 30 milliseconds ago"
                );
            }
        }

        Thread.sleep(1600);
        if (cache.get(1) != null) {
            throw new RuntimeException(
                "Cache supposed to be empty as value last access was more than (idleScanTime * 3) milliseconds ago"
            );
        }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0