code: def test_weakref_cache(tmp_path, cls, expect_cached, size):
      buf = SpillBuffer(str(tmp_path), target=100)
  
      # Run this test twice:
      # - x is smaller than target and is evicted by y;
      # - x is individually larger than target and it never touches fast
      x = cls(size)
      buf["x"] = x
      if size < 100:
          buf["y"] = cls(60)  # spill x
      assert "x" in buf.slow
  
      # Test that we update the weakref cache on setitem
      assert (buf["x"] is x) == expect_cached
  
      # Do not use id_x = id(x), as in CPython id's are C memory addresses and are reused
      # by PyMalloc when you descope objects, so a brand new object might end up having
      # the same id as a deleted one
      id_x = x.id
      del x
  
      # Ensure that the profiler has stopped and released all references to x so that it can be garbage-collected
      with profile.lock:
          pass
  
      if size < 100:
          buf["y"]
      assert "x" in buf.slow
  
      x2 = buf["x"]
      assert x2.id != id_x
      if size < 100:
          buf["y"]
      assert "x" in buf.slow
  
      # Test that we update the weakref cache on getitem
      assert (buf["x"] is x2) == expect_cached
  
imports: from __future__ import annotations
  import array
  import os
  import random
  import uuid
  from pathlib import Path
  import pytest
  import dask.config
  from dask.sizeof import sizeof
  from distributed import profile
  from distributed.compatibility import WINDOWS
  from distributed.metrics import meter
  from distributed.spill import SpillBuffer
  from distributed.utils import RateLimiterFilter
  from distributed.utils_test import captured_logger
label_desc: Use image node_id 11 for calling a global function with example usage: test_weakref_cache(tmp_path, cls, expect_cached, size) without return types