commit
cefe0974d9
2 changed files with 3 additions and 6 deletions
5
lib/ansible/cache/jsonfile.py
vendored
5
lib/ansible/cache/jsonfile.py
vendored
|
@ -17,14 +17,12 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
import errno
|
import errno
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible.cache.base import BaseCacheModule
|
from ansible.cache.base import BaseCacheModule
|
||||||
|
|
||||||
|
|
||||||
class CacheModule(BaseCacheModule):
|
class CacheModule(BaseCacheModule):
|
||||||
"""
|
"""
|
||||||
A caching module backed by json files.
|
A caching module backed by json files.
|
||||||
|
@ -70,12 +68,11 @@ class CacheModule(BaseCacheModule):
|
||||||
|
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
#TODO: check if valid keys can have invalid FS chars, base32?
|
|
||||||
f = open(cachefile, 'w')
|
f = open(cachefile, 'w')
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError), e:
|
||||||
utils.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
utils.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
||||||
else:
|
else:
|
||||||
json.dump(value, f, ensure_ascii=False)
|
f.write(utils.jsonify(value))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
4
lib/ansible/cache/redis.py
vendored
4
lib/ansible/cache/redis.py
vendored
|
@ -20,9 +20,9 @@ import collections
|
||||||
# FIXME: can we store these as something else before we ship it?
|
# FIXME: can we store these as something else before we ship it?
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
|
from ansible.utils import jsonify
|
||||||
from ansible.cache.base import BaseCacheModule
|
from ansible.cache.base import BaseCacheModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +65,7 @@ class CacheModule(BaseCacheModule):
|
||||||
return json.loads(value)
|
return json.loads(value)
|
||||||
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
value2 = json.dumps(value)
|
value2 = jsonify(value)
|
||||||
if self._timeout > 0: # a timeout of 0 is handled as meaning 'never expire'
|
if self._timeout > 0: # a timeout of 0 is handled as meaning 'never expire'
|
||||||
self._cache.setex(self._make_key(key), int(self._timeout), value2)
|
self._cache.setex(self._make_key(key), int(self._timeout), value2)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue