Skip to content

flexicache appears to be LIFO instead of LRU #678

Open
@pydanny

Description

@pydanny

Original example: https://nbsanity.com/static/c829aad0449a13ad7c6d63125e84f51d/timed_cache_bug.html

from fastcore.xtras import flexicache, time_policy
from functools import lru_cache
from random import randint

@lru_cache(maxsize=2)
def lru_func(v): 
    return randint(1, 1000)

@flexicache(maxsize=2)
def flexi_func(v): 
    return randint(1, 1000)

assert lru_func(1) == lru_func(1)
assert lru_func(2) == lru_func(2)
assert lru_func(3) == lru_func(3)
assert lru_func(1) == lru_func(1)

assert flexi_func(1) == flexi_func(1)
assert flexi_func(2) == flexi_func(2)
assert flexi_func(3) == flexi_func(3)
assert flexi_func(1) == flexi_func(1)

The timed_func throws this exception:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[1], line 20
     18 assert flexi_func(1) == flexi_func(1)
     19 assert flexi_func(2) == flexi_func(2)
---> 20 assert flexi_func(3) == flexi_func(3)
     21 assert flexi_func(1) == flexi_func(1)

AssertionError: 

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions