-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace interal cache with dogpile & created a dogpile backend for dj…
…ango cache system :s
- Loading branch information
1 parent
2dddf52
commit 03c8c70
Showing
9 changed files
with
145 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# DuedilApiClient v3 Pro + Credit | ||
# @copyright 2015 Andrew Miller | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
|
||
|
||
from dogpile.cache import make_region | ||
import json | ||
|
||
# from dogpile.cache.proxy import ProxyBackend | ||
# from requests import Response | ||
# from urlparse import urlsplit | ||
# | ||
# class HttpProxy(ProxyBackend): | ||
# def set(self, key, value): | ||
# # value should be a http response object | ||
# assert isinstance(value, Response) | ||
# value = value.json() | ||
# params = value.url | ||
# self.proxied.set(key, value) | ||
|
||
|
||
def kwargs_key_generator(namespace, fn, **kw): | ||
fname = fn.__name__ | ||
def generate_key(*args, **kwargs): | ||
args_str = "_".join(str(s) for s in args) | ||
kwargs_str = json.dumps(kwargs) | ||
return '{}_{}:{}_{}'.format(namespace, fname, args_str, kwargs_str) | ||
return generate_key | ||
|
||
dp_region = make_region(name='duedilv3', function_key_generator = kwargs_key_generator) | ||
|
||
|
||
def configure_cache(backend='dogpile.cache.pylibmc', expiration_time=86400, **kwargs): | ||
if not kwargs: | ||
kwargs = { | ||
'url': ["127.0.0.1"], | ||
} | ||
return dp_region.configure( | ||
backend, | ||
expiration_time = expiration_time, # 1 day | ||
arguments = kwargs | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
from dogpile.cache.api import CacheBackend, NO_VALUE | ||
from dogpile.cache import register_backend | ||
from django.core.cache import get_cache | ||
|
||
register_backend("django_cache", "duedilv3.contrib.django", "DjangoCacheBackend") | ||
|
||
|
||
class DjangoCacheBackend(CacheBackend): | ||
def __init__(self, arguments): | ||
django_cache_name = arguments.pop('cache_name', 'default') | ||
self.cache = get_cache(django_cache_name) | ||
|
||
def get(self, key): | ||
return self.cache.get(key, NO_VALUE) | ||
|
||
def set(self, key, value): | ||
self.cache.set(key, value, self.timeout) | ||
|
||
def delete(self, key): | ||
self.cache.delete(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters