質問

ビーカーキャッシュはTypeErrorをコンパルします。私はGoogleを検索しました、Beakerの号の号の追跡者でさえ、何も見つけることができませんでした。

次の方法のようなクエリをキャッシュする

@staticmethod
def get_queries(query):
    @cache.cache(query, type = 'file', expire = 300)
    def load(query):
        entries = db.get_expensive_query(query)
        return entries
    return load(query)
.

しかし私がプログラムを実行するとき、これは私が受け取るものです

  File "/Users/ivan/project/controller/caching.py", line 15, in get_queries
      return load(query)
  File "/Library/Python/2.6/site-packages/Beaker-1.5.4-py2.6.egg/beaker/cache.py", line 417, in cached
    return cache[0].get_value(cache_key, createfunc=go)
  File "/Library/Python/2.6/site-packages/Beaker-1.5.4-py2.6.egg/beaker/cache.py", line 214, in get
    return self._get_value(key, **kw).get_value()
  File "/Library/Python/2.6/site-packages/Beaker-1.5.4-py2.6.egg/beaker/container.py", line 256, in get_value
    if not self._is_expired(stored, expired):
  File "/Library/Python/2.6/site-packages/Beaker-1.5.4-py2.6.egg/beaker/container.py", line 245, in _is_expired
    time.time() >= expiretime + storedtime
TypeError: cannot concatenate 'str' and 'float' objects
.

私は何か悪いことをしているか、これはビーカーのバグですか?

役に立ちましたか?

解決

Your code calls cache.cache with an integer for expire, which is correct, but clearly either expiretime or storedtime is winding up with a string. [From the error message it has to be expiretime. --ed] So here's what I think happened:

(1) You called cache.cache with a string expire at some point. [Maybe even from the default cache.expire in the CacheManager opts, not sure.]

(2) You fixed the bug, producing the code you submitted (which works for me).

(3) You reran the code without deleting the cache directory, and so somehow it picked up the previous state.

I can reproduce your error by following the above prescription. Could you delete your cache (everything in cache.data_dir and cache.lock_dir) and try again?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top