class_docstr: Class to cache and retrieve the state of an object.
  
  Objects can either be stored in memory or on disk. If stored on disk, they can be
  stored in a given directory, or alternatively a temporary location will be used.
  
  If necessary/possible, restored objects will be returned to their original device.
  
  Example:
  
  >>> state_cacher = StateCacher(memory_cache, cache_dir=cache_dir)
  >>> state_cacher.store("model", model.state_dict())
  >>> model.load_state_dict(state_cacher.retrieve("model"))
class_docstr_tok: ["Class","to","cache","and","retrieve","the","state","of","an","object",".","Objects","can","either","be","stored","in","memory","or","on","disk",".","If","stored","on","disk",",","they","can","be","stored","in","a","given","directory",",","or","alternatively","a","temporary","location","will","be","used",".","If","necessary\/possible",",","restored","objects","will","be","returned","to","their","original","device",".","Example",":",">",">",">","state_cacher","=","StateCacher","(","memory_cache",",","cache_dir=cache_dir",")",">",">",">","state_cacher.store","(","``","model","''",",","model.state_dict","(",")",")",">",">",">","model.load_state_dict","(","state_cacher.retrieve","(","``","model","''",")",")"]
docstr: If necessary, delete any cached files existing in `cache_dir`.
docstr_tok: ["If","necessary",",","delete","any","cached","files","existing","in","`","cache_dir","`","."]
code: def __del__(self):
      """If necessary, delete any cached files existing in `cache_dir`."""
      if not self.in_memory:
          for k in self.cached:
              if os.path.exists(self.cached[k]["obj"]):
                  os.remove(self.cached[k]["obj"])
  
file_path: MONAI/monai/utils/state_cacher.py
imports: from __future__ import annotations
  import copy
  import os
  import pickle
  import tempfile
  from types import ModuleType
  from typing import Any, Hashable
  import torch
  from torch.serialization import DEFAULT_PROTOCOL
  from monai.config.type_definitions import PathLike
label_desc: Use image node_id 4 for calling the StateCacher obj's underlying member method code with example usage: obj.__del__() without return types