Skip to content

Commit

Permalink
[WIP] add fscache
Browse files Browse the repository at this point in the history
  • Loading branch information
lowne committed Oct 22, 2020
1 parent bc3df78 commit 844be8a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_caching import Cache

app = Flask(__name__)
app.config.from_object(Config)
Expand All @@ -11,4 +12,7 @@
login = LoginManager(app)
login.login_view = 'login'

cache = Cache(app,config={'CACHE_TYPE': 'simple'})
fscache = Cache(app,config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': 'app/cache', 'CACHE_THRESHOLD': 10000, 'CACHE_DEFAULT_TIMEOUT': 86400})

from app import routes, models, errors
4 changes: 3 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import wraps
from datetime import datetime
from app import db, login
from app import db, login, fscache
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy.ext.associationproxy import association_proxy
Expand Down Expand Up @@ -141,6 +141,8 @@ class ytPost():
date = 'None'
views = 'NaN'
id = 'isod'

@fscache.memoize()
def get_ytChannel_info(cid):
# https://github.com/pluja/youtube_search-fork/blob/master/youtube_search/__init__.py#L60
# it's just wrong...
Expand Down
5 changes: 1 addition & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
import requests
from flask import Response
from flask import render_template, flash, redirect, url_for, request, send_from_directory, Markup
from flask_caching import Cache
from flask_login import login_user, logout_user, current_user, login_required
from requests_futures.sessions import FuturesSession
from werkzeug.datastructures import Headers
from werkzeug.urls import url_parse
from werkzeug.utils import secure_filename
from youtube_search import YoutubeSearch

from app import app, db, yotterconfig
from app import app, db, yotterconfig, cache, fscache
from app.forms import LoginForm, RegistrationForm, EmptyForm, SearchForm, ChannelForm
from app.models import User, ytChannel, ytPost
from youtube import comments, utils, channel as ytch, search as yts
Expand All @@ -28,8 +27,6 @@

#########################################

cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(app)
##########################
#### Config variables ####
##########################
Expand Down

0 comments on commit 844be8a

Please sign in to comment.