Files
slopvivors/scenes/utils/keyed_cache.gd

18 lines
279 B
GDScript

class_name KeyedCache
extends Resource
var cache = {}
func get_or_compute(key: String, compute_func: Callable):
if key in cache:
return cache["key"]
var value = compute_func.call()
cache["key"] = value
return value
func invalidate_key(key: String):
cache.erase(key)