mirror of
https://github.com/flancian/garden.git
synced 2026-08-08 23:46:19 +00:00
Try the simplest flask cache possible.
This commit is contained in:
@@ -15,11 +15,16 @@
|
||||
import bleach
|
||||
import os
|
||||
from flask import Flask
|
||||
from flask_caching import Cache
|
||||
from flaskext.markdown import Markdown
|
||||
from markdown.extensions.wikilinks import WikiLinkExtension
|
||||
from . import util
|
||||
from flask_cors import CORS
|
||||
|
||||
cache = Cache()
|
||||
|
||||
# what is this doing here, I have no idea.
|
||||
# todo: move to util.
|
||||
def wikilink_to_url(label, base, end):
|
||||
label = util.canonical_wikilink(label)
|
||||
url = '/node/' + label
|
||||
@@ -30,8 +35,12 @@ def create_app(test_config=None):
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
app.config.from_mapping(
|
||||
SECRET_KEY='dev',
|
||||
DEBUG=True, # some Flask specific configs
|
||||
CACHE_TYPE="SimpleCache", # Flask-Caching related configs
|
||||
CACHE_DEFAULT_TIMEOUT=30
|
||||
)
|
||||
CORS(app)
|
||||
cache.init_app(app, config={'CACHE_TYPE': 'SimpleCache', 'CACHE_DEFAULT_TIMEOUT': 30})
|
||||
|
||||
if test_config is None:
|
||||
# load the instance config, if it exists, when not testing
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import cachetools.func
|
||||
import glob
|
||||
import itertools
|
||||
import re
|
||||
import os
|
||||
from flask import current_app
|
||||
from . import cache
|
||||
from . import config
|
||||
from . import feed
|
||||
from . import render
|
||||
@@ -80,7 +80,7 @@ class Graph:
|
||||
nodes = [node for node in G.nodes() if node.wikilink in permutations and node.subnodes]
|
||||
return nodes
|
||||
|
||||
@cachetools.func.ttl_cache(maxsize=2, ttl=20)
|
||||
@cache.memoize(timeout=30)
|
||||
def nodes(self, include_journals=True):
|
||||
current_app.logger.debug('Loading graph.')
|
||||
# returns a list of all nodes
|
||||
@@ -112,7 +112,7 @@ class Graph:
|
||||
# Running something like this would be ideal eventually though.
|
||||
# It might also work better once all pulling/pushing logic moves to Graph, where it belongs,
|
||||
# and can make use of more sensible algorithms.
|
||||
@cachetools.func.ttl_cache(maxsize=2, ttl=20)
|
||||
@cache.memoize(timeout=30)
|
||||
def compute_transclusion(self, include_journals=True):
|
||||
|
||||
# Add artisanal virtual subnodes (resulting from transclusion/[[push]]) to all nodes.
|
||||
@@ -121,7 +121,7 @@ class Graph:
|
||||
node.subnodes.extend(pushed_subnodes)
|
||||
|
||||
# does this belong here?
|
||||
@cachetools.func.ttl_cache(maxsize=1, ttl=20)
|
||||
@cache.memoize(timeout=30)
|
||||
def subnodes(self, sort=lambda x: x.uri.lower()):
|
||||
# Markdown.
|
||||
subnodes = [Subnode(f) for f in glob.glob(os.path.join(config.AGORA_PATH, '**/*.md'), recursive=True)]
|
||||
|
||||
@@ -5,6 +5,7 @@ dateparser==1.0.0
|
||||
feedparser==6.0.2
|
||||
filetype==1.0.7
|
||||
Flask==1.1.2
|
||||
Flask-Caching==1.10.0
|
||||
Flask-Cors==3.0.10
|
||||
Flask-Markdown==0.3
|
||||
Flask-WTF==0.14.3
|
||||
|
||||
Reference in New Issue
Block a user