emmett-framework / emmett

The web framework for inventors
Other
1.04k stars 70 forks source link

Error with cache #272

Closed josejachuf closed 4 years ago

josejachuf commented 4 years ago

Hi @gi0baro

This is using weppy 1.3.3 in development mode

I have two cached functions, one makes a call to the database and the other just returns a list

cache = Cache()

@cache(key='mykey1', duration=300)
def f1():
    rows = MyModel.all().select()
    # With some data from rows I create a dictionary and return it
    return v

@cache(key='mykey2', duration=60)
def f2():
    return [1,2,3]

In this case inside the _get_dbset of weppy-rest I call f1 and f2. But for that matter it would be the same to call her on any route

In the client I have:

window.setInterval(function(){
  /// call function here
}, 1000*60*3);

What I observe is that it randomly throws an error when calling f1 (KeyError: 'mykey1'), but it never gives an error when calling f2

... File "./myapp/controllers/services/my_service.py", line 80, in _get_dbset A = f1() File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 67, in wrap key, lambda: f(*args, *kwargs), self.duration) File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 109, in get_or_set self.set(key, value, duration) File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 83, in wrap return method(self, key, args, **kwargs) File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 97, in wrap expiration=now + duration) File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 186, in set self._prune() File "/venv36/lib/python3.6/site-packages/weppy/cache.py", line 155, in _prune self._heap_acc.remove((self.data[rk].acc, rk)) KeyError: 'mykey1'

The error is not frequent, I have left it making requests from two browsers for ~ 1hr and it happened 5 times

gi0baro commented 4 years ago

@josejachuf can you please test this with current 1.x (39c7447)?

josejachuf commented 4 years ago

Hi @gi0baro This works fine. It was 4 hr and no error occurred. thanks