mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Make BaseFileCache into an abstractbaseclass so it's a proper interface
Push the opening and closing of files into the _load and _dump methods so that we don't invoke the slow codec machinery without reason.
This commit is contained in:
parent
c033e5111f
commit
45251f910c
5 changed files with 66 additions and 48 deletions
16
lib/ansible/plugins/cache/pickle.py
vendored
16
lib/ansible/plugins/cache/pickle.py
vendored
|
@ -30,13 +30,13 @@ class CacheModule(BaseFileCacheModule):
|
|||
"""
|
||||
A caching module backed by pickle files.
|
||||
"""
|
||||
plugin_name = 'pickle'
|
||||
read_mode = 'rb'
|
||||
write_mode = 'wb'
|
||||
encoding = None
|
||||
|
||||
def _load(self, f):
|
||||
return pickle.load(f)
|
||||
def _load(self, filepath):
|
||||
# Pickle is a binary format
|
||||
with open(filepath, 'rb') as f:
|
||||
return pickle.load(f)
|
||||
|
||||
def _dump(self, value, f):
|
||||
pickle.dump(value, f)
|
||||
def _dump(self, value, filepath):
|
||||
with open(filepath, 'wb') as f:
|
||||
# Use pickle protocol 2 which is compatible with Python 2.3+.
|
||||
pickle.dump(value, f, protocol=2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue