intento de manejar cache
This commit is contained in:
parent
bad701fbe2
commit
79ac33ec1d
14
README.md
14
README.md
@ -62,10 +62,19 @@ sudo systemctl restart apache2
|
|||||||
# IMPORTANTE
|
# IMPORTANTE
|
||||||
- Debes de dar permisos a la ruta de archivos UPLOAD (solo se ejecuta una vez)
|
- Debes de dar permisos a la ruta de archivos UPLOAD (solo se ejecuta una vez)
|
||||||
```bash
|
```bash
|
||||||
sudo chown -R www-data:www-data /var/www/uploads/formha
|
sudo chown -R www-data:www-data /var/www/formha/static/uploads
|
||||||
sudo chmod -R 755 /var/www/uploads/formha
|
sudo chmod -R 755 /var/www/formha/static/uploads
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# PERMISOS DEL CACHE
|
||||||
|
Reemplaza www-data por el usuario de Flask/Apache
|
||||||
|
```bash
|
||||||
|
sudo mkdir -p /var/www/formha/cache
|
||||||
|
sudo chown -R www-data:www-data /var/www/formha/cache
|
||||||
|
sudo chmod 700 /var/www/formha/cache
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# BACKUP DB FORMHA
|
# BACKUP DB FORMHA
|
||||||
```psql
|
```psql
|
||||||
n_file="db_formha_backup_$(date +"%d_%m_%Y-%H_%M_%S").sql"
|
n_file="db_formha_backup_$(date +"%d_%m_%Y-%H_%M_%S").sql"
|
||||||
@ -73,3 +82,4 @@ pg_dump -h 127.0.0.1 -U postgres -d formha -f "$n_file"
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
18
main.py
18
main.py
@ -27,18 +27,22 @@ import platform
|
|||||||
|
|
||||||
|
|
||||||
folder_upload = None
|
folder_upload = None
|
||||||
|
folder_cache = None
|
||||||
|
|
||||||
if 'microsoft' in platform.uname().release.lower():
|
if 'microsoft' in platform.uname().release.lower():
|
||||||
# folder_upload = os.path.join(os.getcwd(), "/static/uploads/")
|
# folder_upload = os.path.join(os.getcwd(), "/static/uploads/")
|
||||||
folder_upload = os.path.join(os.getcwd(), "static", "uploads")
|
folder_upload = os.path.join(os.getcwd(), "static", "uploads")
|
||||||
|
folder_cache = os.path.join(os.getcwd(), "cache")
|
||||||
|
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
# folder_upload = "/var/www/uploads/formha"
|
# folder_upload = "/var/www/uploads/formha"
|
||||||
folder_upload = "/var/www/formha/static/uploads/"
|
folder_upload = "/var/www/formha/static/uploads/"
|
||||||
|
folder_cache = "/var/www/formha/cache"
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp/flask-formha'})
|
cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': folder_cache})
|
||||||
|
# cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp/flask-formha'})
|
||||||
|
|
||||||
bcrypt = Bcrypt(app)
|
bcrypt = Bcrypt(app)
|
||||||
# csrf = CSRFProtect(app)
|
# csrf = CSRFProtect(app)
|
||||||
@ -151,7 +155,7 @@ def page_not_found(e):
|
|||||||
return redirect(url_for('home'))
|
return redirect(url_for('home'))
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
# @cache.cached(timeout=3600)
|
@cache.cached(timeout=3600) # 1 hora
|
||||||
def home():
|
def home():
|
||||||
q = """
|
q = """
|
||||||
SELECT
|
SELECT
|
||||||
@ -172,17 +176,17 @@ def home():
|
|||||||
return render_template(v['home'], active_page='home', data=data)
|
return render_template(v['home'], active_page='home', data=data)
|
||||||
|
|
||||||
@app.route('/about-us')
|
@app.route('/about-us')
|
||||||
@cache.cached(timeout=43200)
|
@cache.cached(timeout=43200) # 12 horas
|
||||||
def about_us():
|
def about_us():
|
||||||
return render_template(v['about-us'], active_page='about_us')
|
return render_template(v['about-us'], active_page='about_us')
|
||||||
|
|
||||||
@app.route('/solutions')
|
@app.route('/solutions')
|
||||||
@cache.cached(timeout=43200)
|
@cache.cached(timeout=43200) # 12 horas
|
||||||
def solutions():
|
def solutions():
|
||||||
return render_template(v['solutions'], active_page='solutions')
|
return render_template(v['solutions'], active_page='solutions')
|
||||||
|
|
||||||
@app.route('/methodology')
|
@app.route('/methodology')
|
||||||
# @cache.cached(timeout=43200)
|
@cache.cached(timeout=43200) # 12 horas
|
||||||
def methodology():
|
def methodology():
|
||||||
return render_template(v['methodology'], active_page='methodology')
|
return render_template(v['methodology'], active_page='methodology')
|
||||||
|
|
||||||
@ -191,6 +195,7 @@ def blog():
|
|||||||
return render_template( v['blog']['all_posts'], active_page='blog' )
|
return render_template( v['blog']['all_posts'], active_page='blog' )
|
||||||
|
|
||||||
@app.route('/blog/api/posts')
|
@app.route('/blog/api/posts')
|
||||||
|
@cache.cached(timeout=3600) # 1 hora
|
||||||
def api_posts():
|
def api_posts():
|
||||||
q = r"""
|
q = r"""
|
||||||
SELECT
|
SELECT
|
||||||
@ -213,7 +218,7 @@ def api_posts():
|
|||||||
|
|
||||||
@app.route('/blog/<int:post_id>')
|
@app.route('/blog/<int:post_id>')
|
||||||
@app.route('/blog/<int:post_id>/src/<string:source_name>')
|
@app.route('/blog/<int:post_id>/src/<string:source_name>')
|
||||||
# @cache.cached(timeout=43200)
|
@cache.cached(timeout=1800) # 30 minutos
|
||||||
def blog_post(post_id, source_name=None):
|
def blog_post(post_id, source_name=None):
|
||||||
# source_name = source_name or 'direct'
|
# source_name = source_name or 'direct'
|
||||||
# source_name = source_name.lower()
|
# source_name = source_name.lower()
|
||||||
@ -261,6 +266,7 @@ def blog_post(post_id, source_name=None):
|
|||||||
return render_template(v['blog']['post'], data=data)
|
return render_template(v['blog']['post'], data=data)
|
||||||
|
|
||||||
@app.route('/blog/api/count-post-viewed')
|
@app.route('/blog/api/count-post-viewed')
|
||||||
|
@cache.cached(timeout=1800) # 30 minutos
|
||||||
def count_posts_viewed():
|
def count_posts_viewed():
|
||||||
q = "SELECT id_post, COUNT(id_post) AS count FROM posts_visited GROUP BY id_post ORDER BY id_post;"
|
q = "SELECT id_post, COUNT(id_post) AS count FROM posts_visited GROUP BY id_post ORDER BY id_post;"
|
||||||
data = dbUsers.get_all_data_dict(q)
|
data = dbUsers.get_all_data_dict(q)
|
||||||
|
@ -26,7 +26,21 @@
|
|||||||
Blvd. Adolfo Ruíz Cortines 2467<br>C.P. 16035, CDMX, México
|
Blvd. Adolfo Ruíz Cortines 2467<br>C.P. 16035, CDMX, México
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="mb-2"><i class="bi bi-telephone-fill me-2"></i> +52 xxxx xxxx</li>
|
<!-- <li class="mb-2"><i class="bi bi-telephone-fill me-2"></i>55 3955 0085</li>
|
||||||
|
<li class="mb-2"><i class="bi bi-telephone-fill me-2"></i>55 3332 0378</li> -->
|
||||||
|
<li class="mb-2">
|
||||||
|
<i class="bi bi-telephone-fill me-2"></i>
|
||||||
|
<a href="https://wa.me/525539550085" target="_blank" style="text-decoration: none; color: inherit;">
|
||||||
|
55 3955 0085
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="mb-2">
|
||||||
|
<i class="bi bi-telephone-fill me-2"></i>
|
||||||
|
<a href="https://wa.me/525533320378" target="_blank" style="text-decoration: none; color: inherit;">
|
||||||
|
55 3332 0378
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<!-- <li class="mb-2"><i class="bi bi-envelope-fill me-2"></i> email@formha.com</li> -->
|
<!-- <li class="mb-2"><i class="bi bi-envelope-fill me-2"></i> email@formha.com</li> -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -47,7 +61,7 @@
|
|||||||
<a href="https://x.com/formhamx" target="_blank"><i class="bi bi-twitter-x"></i></a>
|
<a href="https://x.com/formhamx" target="_blank"><i class="bi bi-twitter-x"></i></a>
|
||||||
<a href="https://www.instagram.com/formha.mx" target="_blank"><i class="bi bi-instagram"></i></a>
|
<a href="https://www.instagram.com/formha.mx" target="_blank"><i class="bi bi-instagram"></i></a>
|
||||||
<a href="https://www.linkedin.com/company/formha-mx/" target="_blank"><i class="bi bi-linkedin"></i></a>
|
<a href="https://www.linkedin.com/company/formha-mx/" target="_blank"><i class="bi bi-linkedin"></i></a>
|
||||||
<a href="#" target="_blank"><i class="bi bi-youtube"></i></a>
|
<a href="https://www.youtube.com/channel/UCl0gbhMOlYj7zFEFsai50WQ" target="_blank"><i class="bi bi-youtube"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user