enable caching
This commit is contained in:
		
							parent
							
								
									a783d5a4cc
								
							
						
					
					
						commit
						4e1dcc16dd
					
				
							
								
								
									
										7
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								app.py
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | ||||
| # app.py | ||||
| from flask import Flask, render_template, request, redirect, url_for, session, flash | ||||
| from flask_caching import Cache | ||||
| import requests.auth | ||||
| from lib.datetime import filter_accounts_current_month | ||||
| from lib.reqs import (get_urls, get_user_accounts) | ||||
| @ -10,8 +11,10 @@ from config import DevelopmentConfig  # or ProductionConfig | ||||
| 
 | ||||
| app = Flask(__name__) | ||||
| app.config.from_object(DevelopmentConfig)  # Use DevelopmentConfig or ProductionConfig as needed | ||||
| cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache'}) | ||||
| 
 | ||||
| @app.route('/') | ||||
| @cache.cached(timeout=60)  # cache for 120 seconds | ||||
| def home(): | ||||
|     # If the user is logged in, redirect to a protected page like /accounts | ||||
|     if session.get('logged_in'): | ||||
| @ -52,6 +55,7 @@ def login(): | ||||
|         return render_template('index.html', error=error) | ||||
| 
 | ||||
| @app.route('/urls', methods=['GET']) | ||||
| @cache.cached(timeout=300)  # cache for 5 minutes | ||||
| def urls(): | ||||
|     # Check if the user is logged in | ||||
|     if not session.get('logged_in'): | ||||
| @ -61,13 +65,14 @@ def urls(): | ||||
|     return render_template('urls.html', urls=get_urls(base_url, session['auth_credentials'])) | ||||
| 
 | ||||
| @app.route('/accounts', methods=['GET']) | ||||
| @cache.cached(timeout=120)  # cache for 120 seconds | ||||
| def user_accounts(): | ||||
|     # Check if the user is logged in | ||||
|     if not session.get('logged_in'): | ||||
|         return redirect(url_for('home')) | ||||
|     # Placeholder content for Accounts page | ||||
|     base_url = app.config['BASE_URL']  # Access base_url from the config     | ||||
|     return render_template('user_accounts.html', username=session['username'], user_accounts=get_user_accounts(base_url, session['auth_credentials'])) | ||||
|     return render_template('user_accounts.html', username=session['username'], user_accounts=get_user_accounts(base_url, session['auth_credentials']), auth=session['auth_credentials']) | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     app.run(debug=app.config['DEBUG'], host=app.config['HOST'], port=app.config['PORT']) | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								requirements.txt
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								requirements.txt
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Karl Hudgell
						Karl Hudgell