mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00: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:
committed by
Brian Coca
parent
c033e5111f
commit
45251f910c
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)
|
||||
|
||||
Reference in New Issue
Block a user