Make it possible not to use caching
parent
3aea7cb8da
commit
b66ac2bc5e
|
@ -97,19 +97,23 @@ class Options:
|
||||||
|
|
||||||
class Cache:
|
class Cache:
|
||||||
""" Light, error-prone caching system. """
|
""" Light, error-prone caching system. """
|
||||||
def __init__(self, folder, key, lifespan=10*24*3600):
|
def __init__(self, folder=None, key='cache', lifespan=10*24*3600):
|
||||||
self._key = key
|
self._key = key
|
||||||
self._dir = folder
|
self._dir = folder
|
||||||
self._lifespan = lifespan
|
self._lifespan = lifespan
|
||||||
|
|
||||||
|
self._cache = {}
|
||||||
|
|
||||||
|
if self._dir is None:
|
||||||
|
self._hash = "NO CACHE"
|
||||||
|
return
|
||||||
|
|
||||||
maxsize = os.statvfs('./').f_namemax - len(self._dir) - 1 - 4 # ".tmp"
|
maxsize = os.statvfs('./').f_namemax - len(self._dir) - 1 - 4 # ".tmp"
|
||||||
self._hash = urllib.quote_plus(self._key)[:maxsize]
|
self._hash = urllib.quote_plus(self._key)[:maxsize]
|
||||||
|
|
||||||
self._file = self._dir + '/' + self._hash
|
self._file = self._dir + '/' + self._hash
|
||||||
self._file_tmp = self._file + '.tmp'
|
self._file_tmp = self._file + '.tmp'
|
||||||
|
|
||||||
self._cache = {}
|
|
||||||
|
|
||||||
if os.path.isfile(self._file):
|
if os.path.isfile(self._file):
|
||||||
data = open(self._file).read()
|
data = open(self._file).read()
|
||||||
if data:
|
if data:
|
||||||
|
@ -135,7 +139,7 @@ class Cache:
|
||||||
__setitem__ = set
|
__setitem__ = set
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if len(self._cache) == 0:
|
if len(self._cache) == 0 or self._dir is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not os.path.exists(self._dir):
|
if not os.path.exists(self._dir):
|
||||||
|
@ -643,7 +647,7 @@ def After(rss, options):
|
||||||
else:
|
else:
|
||||||
return rss.tostring(xml_declaration=True, encoding='UTF-8')
|
return rss.tostring(xml_declaration=True, encoding='UTF-8')
|
||||||
|
|
||||||
def process(url, cache, options=None):
|
def process(url, cache=None, options=None):
|
||||||
if options == None:
|
if options == None:
|
||||||
options = []
|
options = []
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue