xref: /aosp_15_r20/external/chromium-trace/catapult/devil/devil/utils/decorators.py (revision 1fa4b3da657c0e9ad43c0220bacf9731820715a5)
1# Copyright 2021 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import functools
6
7
8def Memoize(f):
9  """Decorator to cache return values of function."""
10  memoize_dict = {}
11  @functools.wraps(f)
12  def wrapper(*args, **kwargs):
13    key = repr((args, kwargs))
14    if key not in memoize_dict:
15      memoize_dict[key] = f(*args, **kwargs)
16    return memoize_dict[key]
17  return wrapper
18