1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #14030 from matburt/add_rax_inventory_custom_cache_timeout

Add a config option for rackspace inventory cache
This commit is contained in:
Matt Martz 2016-01-20 14:32:54 -06:00
commit 3bda79ca96
2 changed files with 13 additions and 1 deletions

View file

@ -55,3 +55,12 @@
# will be ignored, and 4 will be used. Accepts a comma separated list, # will be ignored, and 4 will be used. Accepts a comma separated list,
# the first found wins. # the first found wins.
# access_ip_version = 4 # access_ip_version = 4
# Environment Variable: RAX_CACHE_MAX_AGE
# Default: 600
#
# A configuration the changes the behavior or the inventory cache.
# Inventory listing performed before this value will be returned from
# the cache instead of making a full request for all inventory. Setting
# this value to 0 will force a full request.
# cache_max_age = 600

View file

@ -355,9 +355,12 @@ def get_cache_file_path(regions):
def _list(regions, refresh_cache=True): def _list(regions, refresh_cache=True):
cache_max_age = int(get_config(p, 'rax', 'cache_max_age',
'RAX_CACHE_MAX_AGE', 600))
if (not os.path.exists(get_cache_file_path(regions)) or if (not os.path.exists(get_cache_file_path(regions)) or
refresh_cache or refresh_cache or
(time() - os.stat(get_cache_file_path(regions))[-1]) > 600): (time() - os.stat(get_cache_file_path(regions))[-1]) > cache_max_age):
# Cache file doesn't exist or older than 10m or refresh cache requested # Cache file doesn't exist or older than 10m or refresh cache requested
_list_into_cache(regions) _list_into_cache(regions)