Pick caching backend via env vars
This commit is contained in:
@@ -101,8 +101,6 @@ def cgi_app(environ, start_response):
|
||||
|
||||
headers['content-type'] += '; charset=utf-8'
|
||||
|
||||
crawler.default_cache = crawler.SQLiteCache(os.path.join(os.getcwd(), 'morss-cache.db'))
|
||||
|
||||
# get the work done
|
||||
url, rss = FeedFetch(url, options)
|
||||
|
||||
|
@@ -2,7 +2,6 @@ import sys
|
||||
import os.path
|
||||
import argparse
|
||||
|
||||
from . import crawler
|
||||
from .morss import FeedFetch, FeedGather, FeedFormat
|
||||
from .morss import Options
|
||||
|
||||
@@ -44,8 +43,6 @@ def cli_app():
|
||||
options = Options(vars(parser.parse_args()))
|
||||
url = options.url
|
||||
|
||||
crawler.default_cache = crawler.SQLiteCache(os.path.expanduser('~/.cache/morss-cache.db'))
|
||||
|
||||
url, rss = FeedFetch(url, options)
|
||||
rss = FeedGather(rss, url, options)
|
||||
out = FeedFormat(rss, options, 'unicode')
|
||||
|
@@ -388,9 +388,6 @@ class HTTPRefreshHandler(BaseHandler):
|
||||
https_response = http_response
|
||||
|
||||
|
||||
default_cache = {}
|
||||
|
||||
|
||||
class CacheHandler(BaseHandler):
|
||||
" Cache based on etags/last-modified "
|
||||
|
||||
@@ -659,6 +656,22 @@ class MySQLCacheHandler(BaseCache):
|
||||
(url,) + value + value)
|
||||
|
||||
|
||||
if 'CACHE' in os.environ:
|
||||
if os.environ['CACHE'] == 'mysql':
|
||||
default_cache = MySQLCacheHandler(
|
||||
user = os.getenv('MYSQL_USER'),
|
||||
password = os.getenv('MYSQL_PWD'),
|
||||
database = os.getenv('MYSQL_DB'),
|
||||
host = os.getenv('MYSQL_HOST')
|
||||
)
|
||||
|
||||
elif os.environ['CACHE'] == 'sqlite':
|
||||
default_cache = SQLiteCache(os.getenv('SQLITE_PATH', ':memory:'))
|
||||
|
||||
else:
|
||||
default_cache = {}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
req = adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it')
|
||||
|
||||
|
Reference in New Issue
Block a user