Skip to content

Add support for default value in get() #159

Closed
@samupl

Description

@samupl

I opened a PR that adds optional support for default keyword argument in get() method: #158

This is due to a bug I've found in one of the projects I work for, that's Django based. We've noticed that using django's MemcachedCache backend class makes it impossible to save None into the cache without the cache framework thinking that no key is available. E.g.:

With django-redis RedisCache:

>>> cache.set('key', None, 10000)
True
>>> cache.get('key', default=123)
None

With django's MemcachedCache (issue is seen here, get() should return None):

>>> from django.core.cache.backends.memcached import MemcachedCache
>>> mc1 = MemcachedCache('127.0.0.1', {})
>>> mc1.set('key', None, timeout=3600)
>>> mc1.get('key', default=123)
123

PylibMC (an alternative to python-memcached) supports the default param correctly (although it's Django backend is also broken). If this issue gets fixed, I'll push a PR to django to use the new capabilities correctly.

The PR I mentioned adds support for the default keywords and makes it possible for someone to retrieve None from the backend knowing if he set it there explicitly, or if the key is simply missing.

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