class_docstr: Mixin to add caching to a class.
  
  This class is a thin layer on top of joblib.Memory, that mainly adds a
  "caching level", similar to a "log level".
  
  Notes
  -----
  Usage: to cache the results of a method, wrap it in self._cache()
  defined by this class. Caching is performed only if the user-specified
  cache level (self._memory_level) is greater than the value given as a
  parameter to self._cache(). See _cache() documentation for details.
docstr: Return a joblib.Memory object.
  
  The memory_level determines the level above which the wrapped
  function output is cached. By specifying a numeric value for
  this level, the user can to control the amount of cache memory
  used. This function will cache the function call or not
  depending on the cache level.
  
  Parameters
  ----------
  func : function
      The function the output of which is to be cached.
  
  func_memory_level : int, default=1
      The memory_level from which caching must be enabled for the wrapped
      function.
  
  shelve : bool, default=False
      Whether to return a joblib MemorizedResult, callable by a .get()
      method, instead of the return value of func.
  
  Returns
  -------
  mem : joblib.MemorizedFunc, wrapped in _ShelvedFunc if shelving
      Object that wraps the function func to cache its further call.
      This object may be a no-op, if the requested level is lower
      than the value given to _cache()).
      For consistency, a callable object is always returned.
code: def _cache(self, func, func_memory_level=1, shelve=False, **kwargs):
      """Return a joblib.Memory object.
  
      The memory_level determines the level above which the wrapped
      function output is cached. By specifying a numeric value for
      this level, the user can to control the amount of cache memory
      used. This function will cache the function call or not
      depending on the cache level.
  
      Parameters
      ----------
      func : function
          The function the output of which is to be cached.
  
      func_memory_level : int, default=1
          The memory_level from which caching must be enabled for the wrapped
          function.
  
      shelve : bool, default=False
          Whether to return a joblib MemorizedResult, callable by a .get()
          method, instead of the return value of func.
  
      Returns
      -------
      mem : joblib.MemorizedFunc, wrapped in _ShelvedFunc if shelving
          Object that wraps the function func to cache its further call.
          This object may be a no-op, if the requested level is lower
          than the value given to _cache()).
          For consistency, a callable object is always returned.
  
      """
      verbose = getattr(self, "verbose", 0)
  
      # Creates attributes if they don't exist
      # This is to make creating them in __init__() optional.
      if not hasattr(self, "memory_level"):
          self.memory_level = 0
      if not hasattr(self, "memory"):
          self.memory = Memory(location=None, verbose=verbose)
      self.memory = _check_memory(self.memory, verbose=verbose)
  
      # If cache level is 0 but a memory object has been provided, set
      # memory_level to 1 with a warning.
      if self.memory_level == 0 and self.memory.location is not None:
          warnings.warn(
              "memory_level is currently set to 0 but "
              "a Memory object has been provided. "
              "Setting memory_level to 1."
          )
          self.memory_level = 1
  
      return cache(
          func,
          self.memory,
          func_memory_level=func_memory_level,
          memory_level=self.memory_level,
          shelve=shelve,
          **kwargs,
      )
  
file_path: nilearn/nilearn/_utils/cache_mixin.py
imports: import os
  import warnings
  from joblib import Memory
  import nilearn
  from .helpers import stringify_path
label_desc: Use image node_id 1 for calling the CacheMixin obj's underlying member method code with example usage: obj._cache(func, func_memory_level, shelve) and returns: cache