Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use memory cache
  • Loading branch information
Kilo59 committed Apr 27, 2020
commit 609345b56420d1da1fbae90d1a5a455ff2c77c2a
53 changes: 53 additions & 0 deletions app/caches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""app.caches.py"""
# from walrus import Database
import logging
import asyncio
import functools

import aiocache

import config

LOGGER = logging.getLogger(name="app.caches")

SETTINGS = config.get_settings()

if SETTINGS.rediscloud_url:
REDIS_URL = SETTINGS.rediscloud_url
else:
REDIS_URL = SETTINGS.local_redis_url


@functools.lru_cache()
def get_cache(namespace, redis=False) -> aiocache.RedisCache:
"""Retunr """
if redis:
return aiocache.RedisCache(
endpoint=REDIS_URL.host,
port=REDIS_URL.port,
password=REDIS_URL.password,
namespace=namespace,
create_connection_timeout=5,
)
return aiocache.SimpleMemoryCache(namespace=namespace)


CACHE = get_cache("test", redis=False)


async def cach_test():
try:
await CACHE.set("foo", {"foobar": "bar"}, ttl=30)
except OSError as redis_err:
LOGGER.error(f"Redis Error: {redis_err}")
return
print(await CACHE.get("foo"))
await CACHE.close()


if __name__ == "__main__":
# print(REDIS_DB)
# h = REDIS_DB.Hash("Test Hash")
# h["foo"] = "bar"
# print(h)
asyncio.get_event_loop().run_until_complete(cach_test())
45 changes: 0 additions & 45 deletions app/redis_cache.py

This file was deleted.