from flask import Blueprint, render_template import json from cachetools import cached, TTLCache # Create a Blueprint instance cache_bp = Blueprint('cache', __name__, template_folder='templates') # Configure cache with a time-to-live (TTL) of 3600 seconds (1 hour) cache = TTLCache(maxsize=100, ttl=3600) def load_cache(): """Load cache from cache.json""" try: with open('cache.json', 'r') as file: data = json.load(file) for key, value in data.items(): cache[key] = value except FileNotFoundError: print("cache.json not found") @cache_bp.route('/show_cache') @cached(cache) def index(): """Render the HTML page with cached items""" load_cache() return render_template('show_cache.html', bioguideId=cache.get('bioguideId', {}), legislation=cache.get('legislation', {}))