Skip to content

Commit

Permalink
use lru_cache instead of cache to support antiquated systems
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 10, 2023
1 parent 2ed60fb commit d8f6d37
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ssg/components.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
from __future__ import print_function

from collections import defaultdict
from functools import cache
import os

import ssg.yaml


@cache # A speed up cache. We have been opening these same 150 files 300 times per a product build.
try:
from functools import lru_cache
except ImportError: # Viva la python 2.7
from functools import wraps
def lru_cache(max_size, user_function):
cache = {}
@wraps(user_function)
def wrapper(*args):
key = tuple(args)
if key not in cache:
cache[key] = user_function(*args)
return cache[key]
return wrapper

@lru_cache(max_size=16) # A speed up cache. We have been opening these same 150 files 300 times per a product build.
def load(components_dir):
components = {}
for component_filename in os.listdir(components_dir):
Expand Down

0 comments on commit d8f6d37

Please sign in to comment.