class_docstr: Helper for caching function results to on-disk zarr arrays.
  
  It is recommended to use this class through the :func:`cache_to_zarr_if`
  decorator rather than using it directly.
  
  Currently the cache does not perform any limiting or removal of cache
  content. That is left up to the user to manage. Caching is based on
  arguments passed to the decorated function but will only be performed
  if the arguments are of a certain type (see ``uncacheable_arg_types``).
  The cache value to use is purely based on the hash value of all of the
  provided arguments along with the "cache version" (see below).
  
  Note that the zarr format requires regular chunking of data. That is,
  chunks must be all the same size per dimension except for the last chunk.
  To work around this limitation, this class will determine a good regular
  chunking based on the existing chunking scheme, rechunk the input
  arguments, and then rechunk the results before returning them to the user.
  This rechunking is only done if caching is enabled.
  
  Args:
      func: Function that will be called to generate the value to cache.
      cache_config_key: Name of the boolean ``satpy.config`` parameter to
          use to determine if caching should be done.
      uncacheable_arg_types: Types that if present in the passed arguments
          should trigger caching to *not* happen. By default this includes
          ``SwathDefinition``, ``xr.DataArray``, and ``da.Array`` objects.
      sanitize_args_func: Optional function to call to sanitize provided
          arguments before they are considered for caching. This can be used
          to make arguments more "cacheable" by replacing them with similar
          values that will result in more cache hits. Note that the sanitized
          arguments are only passed to the underlying function if caching
          will be performed, otherwise the original arguments are passed.
      cache_version: Version number used to distinguish one version of a
          decorated function from future versions.
  
  Notes:
      * Caching only supports dask array values.
  
      * This helper allows for an additional ``cache_dir`` parameter to
        override the use of the ``satpy.config`` ``cache_dir`` parameter.
  
  Examples:
      To use through the :func:`cache_to_zarr_if` decorator::
  
          @cache_to_zarr_if("cache_my_stuff")
          def generate_my_stuff(area_def: AreaDefinition, some_factor: int) -> da.Array:
              # Generate
              return my_dask_arr
  
      To use the decorated function::
  
          with satpy.config.set(cache_my_stuff=True):
              my_stuff = generate_my_stuff(area_def, 5)
class_docstr_tok: ["Helper","for","caching","function","results","to","on-disk","zarr","arrays",".","It","is","recommended","to","use","this","class","through","the",":","func",":","`","cache_to_zarr_if","`","decorator","rather","than","using","it","directly",".","Currently","the","cache","does","not","perform","any","limiting","or","removal","of","cache","content",".","That","is","left","up","to","the","user","to","manage",".","Caching","is","based","on","arguments","passed","to","the","decorated","function","but","will","only","be","performed","if","the","arguments","are","of","a","certain","type","(","see","``","uncacheable_arg_types","``",")",".","The","cache","value","to","use","is","purely","based","on","the","hash","value","of","all","of","the","provided","arguments","along","with","the","``","cache","version","''","(","see","below",")",".","Note","that","the","zarr","format","requires","regular","chunking","of","data",".","That","is",",","chunks","must","be","all","the","same","size","per","dimension","except","for","the","last","chunk",".","To","work","around","this","limitation",",","this","class","will","determine","a","good","regular","chunking","based","on","the","existing","chunking","scheme",",","rechunk","the","input","arguments",",","and","then","rechunk","the","results","before","returning","them","to","the","user",".","This","rechunking","is","only","done","if","caching","is","enabled",".","Args",":","func",":","Function","that","will","be","called","to","generate","the","value","to","cache",".","cache_config_key",":","Name","of","the","boolean","``","satpy.config","``","parameter","to","use","to","determine","if","caching","should","be","done",".","uncacheable_arg_types",":","Types","that","if","present","in","the","passed","arguments","should","trigger","caching","to","*","not","*","happen",".","By","default","this","includes","``","SwathDefinition","``",",","``","xr.DataArray","``",",","and","``","da.Array","``","objects",".","sanitize_args_func",":","Optional","function","to","call","to","sanitize","provided","arguments","before","they","are","considered","for","caching",".","This","can","be","used","to","make","arguments","more","``","cacheable","''","by","replacing","them","with","similar","values","that","will","result","in","more","cache","hits",".","Note","that","the","sanitized","arguments","are","only","passed","to","the","underlying","function","if","caching","will","be","performed",",","otherwise","the","original","arguments","are","passed",".","cache_version",":","Version","number","used","to","distinguish","one","version","of","a","decorated","function","from","future","versions",".","Notes",":","*","Caching","only","supports","dask","array","values",".","*","This","helper","allows","for","an","additional","``","cache_dir","``","parameter","to","override","the","use","of","the","``","satpy.config","``","``","cache_dir","``","parameter",".","Examples",":","To","use","through","the",":","func",":","`","cache_to_zarr_if","`","decorator",":",":","@","cache_to_zarr_if","(","``","cache_my_stuff","''",")","def","generate_my_stuff","(","area_def",":","AreaDefinition",",","some_factor",":","int",")","-",">","da.Array",":","#","Generate","return","my_dask_arr","To","use","the","decorated","function",":",":","with","satpy.config.set","(","cache_my_stuff=True",")",":","my_stuff","=","generate_my_stuff","(","area_def",",","5",")"]
code: def _get_cache_dir_from_config(cache_dir: Optional[str]) -> str:
      cache_dir = cache_dir or satpy.config.get("cache_dir")
      if cache_dir is None:
          raise RuntimeError(
              "Can't use zarr caching. No 'cache_dir' configured."
          )
      return cache_dir
  
imports: from __future__ import annotations
  import hashlib
  import os
  import shutil
  import warnings
  from datetime import datetime
  from functools import update_wrapper
  from glob import glob
  from typing import Any, Callable, Optional, Union
  import dask
  import numpy
  import xarray
  from dask import array
  from pyorbital.astronomy import cos_zen
  from pyorbital.astronomy import get_alt_az
  from pyorbital.orbital import get_observer_look
  from pyresample.geometry import AreaDefinition, StackedAreaDefinition, SwathDefinition
  import satpy
  from satpy.utils import PerformanceWarning, get_satpos, ignore_invalid_float_warnings
label_desc: Use image node_id 7 for calling the ZarrCacheHelper obj's underlying member method code with example usage: obj._get_cache_dir_from_config(cache_dir) and returns: cache_dir