from pymemcache.client.base import Client
from pymemcache import serde

import constants


class DummyClient:
    _data = {}
    def set(self, key, value, **kwargs):
        self._data[key] = value

    def set_many(self, data, **kwargs):
        self._data.update(data)

    def get(self, key, **kwargs):
        return self._data[key]


if constants.MEMCACHED_HOST_PATH is None:
    client = DummyClient()
else:
    client = Client(
        constants.MEMCACHED_HOST_PATH,
        timeout=1,
        allow_unicode_keys=True,
        encoding='utf-8',
        serde=serde.pickle_serde
    )
