MCPcopy Index your code
hub / github.com/saltstack/salt / _get_cache

Function _get_cache

salt/cache/mmap_cache.py:140–183  ·  view source on GitHub ↗

Return (or lazily create) the ``MmapCache`` instance for *bank* under *cachedir*.

(bank, cachedir)

Source from the content-addressed store, hash-verified

138
139
140def _get_cache(bank, cachedir):
141 """
142 Return (or lazily create) the ``MmapCache`` instance for *bank* under
143 *cachedir*.
144 """
145 key = (cachedir, bank)
146 tuning = _mmap_tuning_tuple()
147 entry = _caches.get(key)
148 if entry is not None:
149 old_tuning, cache_obj = entry
150 if old_tuning == tuning:
151 return cache_obj
152 index_path = cache_obj.path
153 try:
154 cache_obj.close()
155 except (BufferError, OSError):
156 pass
157 del _caches[key]
158 _unlink_mmap_bank_files(index_path)
159
160 bank_dir = salt.utils.path.join(cachedir, os.path.normpath(bank))
161 os.makedirs(bank_dir, exist_ok=True)
162 index_path = os.path.join(bank_dir, ".mmap_cache.idx")
163
164 size, slot_size, key_size = tuning
165 # Heap segment cap controls "how big can a single .heap-N file get
166 # before the next append rolls a new segment". Pulled from opts
167 # rather than hardcoded so operators can tune for filesystems or
168 # backup tools that struggle past a given size. Not part of the
169 # ``tuning`` tuple because changing it does not invalidate
170 # already-written segments — it only affects future appends.
171 max_segment_bytes = __opts__.get(
172 "mmap_cache_max_segment_bytes",
173 salt.utils.mmap_cache.DEFAULT_MAX_SEGMENT_BYTES,
174 )
175 cache_obj = salt.utils.mmap_cache.MmapCache(
176 path=index_path,
177 size=size,
178 slot_size=slot_size,
179 key_size=key_size,
180 max_segment_bytes=max_segment_bytes,
181 )
182 _caches[key] = (tuning, cache_obj)
183 return cache_obj
184
185
186def store(bank, key, data, cachedir, **kwargs):

Callers 7

storeFunction · 0.70
fetchFunction · 0.70
updatedFunction · 0.70
flush_Function · 0.70
list_Function · 0.70
list_allFunction · 0.70
containsFunction · 0.70

Calls 4

closeMethod · 0.95
_mmap_tuning_tupleFunction · 0.85
_unlink_mmap_bank_filesFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected