MCPcopy
hub / github.com/saltstack/salt / store

Method store

salt/cache/__init__.py:131–169  ·  view source on GitHub ↗

Store data using the specified module :param bank: The name of the location inside the cache which will hold the key and its associated data. :param key: The name of the key (or file inside a directory) which will hold the da

(self, bank, key, data, expires=None)

Source from the content-addressed store, hash-verified

129 return data
130
131 def store(self, bank, key, data, expires=None):
132 """
133 Store data using the specified module
134
135 :param bank:
136 The name of the location inside the cache which will hold the key
137 and its associated data.
138
139 :param key:
140 The name of the key (or file inside a directory) which will hold
141 the data. File extensions should not be provided, as they will be
142 added by the driver itself.
143
144 :param data:
145 The data which will be stored in the cache. This data should be
146 in a format which can be serialized by msgpack.
147
148 :param expires:
149 how many seconds from now the data should be considered stale.
150
151 :raises SaltCacheError:
152 Raises an exception if cache driver detected an error accessing data
153 in the cache backend (auth, permissions, etc).
154 """
155 fun = f"{self.driver}.store"
156 try:
157 return self.modules[fun](bank, key, data, expires=expires, **self.kwargs)
158 except TypeError:
159 # if the backing store doesnt natively support expiry, we handle it as a fallback
160 if expires:
161 expires_at = datetime.datetime.now().astimezone() + datetime.timedelta(
162 seconds=expires
163 )
164 expires_at = int(expires_at.timestamp())
165 return self.modules[fun](
166 bank, key, {"data": data, "_expires": expires_at}, **self.kwargs
167 )
168 else:
169 return self.modules[fun](bank, key, data, **self.kwargs)
170
171 def fetch(self, bank, key):
172 """

Calls 1

nowMethod · 0.80