Skip to content

Commit

Permalink
utilities: cached_graph_function: expose inner function using lru_cache
Browse files Browse the repository at this point in the history
as cached_hashable_graph_function, to allow accessing or clearing cache
  • Loading branch information
kmantel committed May 16, 2024
1 parent bf3ba58 commit fb8cb90
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/graph_scheduler/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import inspect
import logging
import weakref
from typing import Dict, Hashable, List, Set, Union
from typing import Callable, Dict, Hashable, List, Set, Union

import networkx as nx

Expand Down Expand Up @@ -262,18 +262,19 @@ def output_graph_image(
print(f'graph_scheduler.output_graph_image: wrote {format} to {filename}')


@functools.lru_cache()
def cached_hashable_graph_function(func: Callable, graph: HashableDict):
return func(graph)


def cached_graph_function(func):
"""
Decorator that can be applied to cache the results of a function
that takes a graph dependency dict
"""
@functools.lru_cache()
def cached_orig_func(graph: HashableDict):
return func(graph)

@functools.wraps(func)
def graph_function_wrapper(graph: typing_graph_dependency_dict):
return cached_orig_func(HashableDict(graph))
return cached_hashable_graph_function(func, HashableDict(graph))

return graph_function_wrapper

Expand Down

0 comments on commit fb8cb90

Please sign in to comment.