Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 11 additions & 12 deletions caching/cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: future_fstrings -*-
import pickle
from collections import OrderedDict
from functools import wraps
Expand Down Expand Up @@ -65,14 +66,14 @@ def __init__(
results only in case of the exceptions are raisd in the
decorated function.
"""
self.params = OrderedDict(
maxsize=maxsize,
ttl=ttl,
filepath=filepath,
policy=policy,
key=key,
only_on_errors=only_on_errors,
**kwargs,
self.params = OrderedDict([
('maxsize', maxsize),
('ttl', ttl),
('filepath', filepath),
('policy', policy),
('key', key),
('only_on_errors', only_on_errors)] +
list(kwargs.items())
)
self.only_on_errors = only_on_errors
self.make_key = key
Expand All @@ -84,10 +85,8 @@ def __init__(
)

def __repr__(self):
return (
f"{self.__class__.__name__}"
f"({', '.join(f'{k}={repr(v)}' for k,v in self.params.items())})"
)
param_str = ', '.join(f'{k}={repr(v)}' for k, v in self.params.items())
return f'{self.__class__.__name__}({param_str})'

def _decorator(self, fn):
if not callable(fn):
Expand Down
10 changes: 5 additions & 5 deletions caching/storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: future_fstrings -*-
import os
import sqlite3
from contextlib import suppress
Expand Down Expand Up @@ -92,10 +93,8 @@ def __repr__(self):
(p, getattr(self, p))
for p in ('filepath', 'maxsize', 'ttl')
)
return (
f'{self.__class__.__name__}'
f"({', '.join(f'{k}={repr(v)}' for k,v in params)})"
)
param_str = ', '.join(f'{k}={repr(v)}' for k, v in params)
return f'{self.__class__.__name__}({param_str})'

def __enter__(self):
self.init_db()
Expand Down Expand Up @@ -152,11 +151,12 @@ def init_db(self):
''')

with self.db as db:
addnl_col_str = ''.join(f"{c}, " for c in policy_stuff['additional_columns'])
db.execute(f'''
CREATE TABLE IF NOT EXISTS cache (
key BINARY PRIMARY KEY,
ts REAL NOT NULL DEFAULT ({self.SQLITE_TIMESTAMP}),
{''.join(f"{c}, " for c in policy_stuff['additional_columns'])}
{addnl_col_str}
value BLOB NOT NULL
) WITHOUT ROWID
''')
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ def run_tests(self):
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
install_requires=['future-fstrings'],
setup_requires=['future-fstrings'],
tests_require=['pytest'],
cmdclass={'test': PyTest},
)
1 change: 1 addition & 0 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: future_fstrings -*-
import os
import time

Expand Down
1 change: 1 addition & 0 deletions tests/test_storage_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: future_fstrings -*-
import os

import pytest
Expand Down