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
19 changes: 14 additions & 5 deletions portale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from urllib.parse import urljoin
from walrus import Database

db = Database()
cache = db.cache()


class BaseRequest:
def __init__(self, session, type, path, cache_ttl=None):
self.db = session.db
self.session_cache = session.db.cache()

self.cache_ttl = cache_ttl if cache_ttl is not None else session.cache_ttl
self.cache_on = bool(self.cache_ttl)
self.session = session
Expand All @@ -26,7 +26,7 @@ def __init__(self, session, type, path, cache_ttl=None):
self.path = path
self.send = self.method()
if self.cache_on:
deco = cache.cached(self.key_fn, timeout=self.cache_ttl, metrics=True)
deco = self.session_cache.cached(self.key_fn, timeout=self.cache_ttl, metrics=True)
self.send = deco(self.send)
self.cache = self.send
f = string.Formatter()
Expand Down Expand Up @@ -73,7 +73,16 @@ def prep_payload(self, payload):


class PrefixedURLSession(requests.Session):
def __init__(self, baseurl, *args, headers=None, cache_ttl=0, logger=None, **kw):
def __init__(self, baseurl, *args, headers=None, cache_ttl=0,
logger=None, redis_host='localhost', redis_port=6379,
redis_db=0, redis_password=None, redis_socket_timeout=None, **kw
):
self.db = Database(
host=redis_host, port=redis_port,
db=redis_db, password=redis_password,
socket_timeout=redis_socket_timeout
)

super(PrefixedURLSession, self).__init__(*args, **kw)
self.baseurl = baseurl
self.cache_ttl = cache_ttl
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="portale",
version="0.9.2",
version="0.9.3",
url="http://pypi.python.org/pypi/portale/",
classifiers=["Programming Language :: Python :: 3"],
include_package_data=True,
Expand Down