code: def memoized(maxsize: int = 1024) -> Callable[[_F], _F]:
      """
      Memoization decorator for immutable classes and pure functions.
      """
  
      def decorator(obj: _F) -> _F:
          cache: SimpleCache[Hashable, Any] = SimpleCache(
              maxsize=maxsize
          )
  
          @wraps(obj)
          def new_callable(*a: Any, **kw: Any) -> Any:
              def create_new() -> Any:
                  return obj(*a, **kw)
  
              key = (a, tuple(sorted(kw.items())))
              return cache.get(key, create_new)
  
          return cast(_F, new_callable)
  
      return decorator
  
file_path: catboost/contrib/python/prompt-toolkit/py3/prompt_toolkit/cache.py
imports: from __future__ import annotations
  from collections import deque
  from functools import wraps
  from typing import Any, Callable, Dict, Generic, Hashable, Tuple, TypeVar, cast
label_desc: Use image node_id 1 for calling a global function with example usage: memoized(maxsize) and returns: decorator, cast, cache, obj