Skip to content

_memoize_version generates invalid keys #131

@xealot

Description

@xealot

The function _memoize_version which is used within the @cache.memoize() decorator can generate keys that are invalid for memcached.

I am using pylibmc==1.5.0 and Flask-Cache==0.13.1

I instantiate the pylibmc client with the behavior of verify_keys.

cache = Cache(app, config={
    'CACHE_TYPE': 'memcached',
    # The reason we pass in a client directly is because the keys that flask-cache uses somehow break
    # in Python 3. I don't know why, but I managed to trace the code far enough to know that if we were
    # to send a client directly in then the Werkzeug cache backend would use it directly. This, as far
    # as I know is the only way to get Pylibmc options into the client init.
    'CACHE_MEMCACHED_SERVERS': pylibmc.Client(['127.0.0.1:11211'], behaviors={'verify_keys': True}),
})

The reason I do this is because when I switched to Python 3 the cache keys were breaking and verify keys seemed to fix it. As I look back on it now, maybe instead of fixing it it simply caused the errors to be hidden.

I see two potential issues:

  1. You do not look at the response from the set command to see if the set was successful, thus hiding potential issues when setting a key does not succeed.
  2. Some functions use raw un-hashed keys which are incompatible with some cache backends.

Switching my client from pylibmc to python-memcached it properly throws an exception for bad key errors coming from _memoize_version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions