Debian Codegraph @

lib/ansible/plugins/cache/memory.py

raw
1 # (c) 2014, Brian Coca, Josh Drake, et al
2 # (c) 2017 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5
6 from __future__ import annotations
7
8 DOCUMENTATION = """
9 name: memory
10 short_description: RAM backed, non persistent
11 description:
12 - RAM backed cache that is not persistent.
13 - This is the default used if no other plugin is specified.
14 - There are no options to configure.
15 version_added: historical
16 author: core team (@ansible-core)
17 """
18
19 from ansible.plugins.cache import BaseCacheModule
20
21
22 class CacheModule(BaseCacheModule):
23 _persistent = False # prevent unnecessary JSON serialization and key munging
24
25 def __init__(self, *args, **kwargs):
26 super().__init__(*args, **kwargs)
27
28 self._cache = {}
29
30 def get(self, key):
31 return self._cache[key]
32
33 def set(self, key, value):
34 self._cache[key] = value
35
36 def keys(self):
37 return self._cache.keys()
38
39 def contains(self, key):
40 return key in self._cache
41
42 def delete(self, key):
43 del self._cache[key]
44
45 def flush(self):
46 self._cache = {}