summaryrefslogtreecommitdiff
path: root/ironicclient/common/filecache.py
diff options
context:
space:
mode:
authorMichael Davies <michael@the-davies.net>2016-06-27 10:05:07 +0000
committerMichael Davies <michael@the-davies.net>2016-06-29 05:12:45 +0000
commit8c811afcab451cd2bced3776dac90228ef7fb565 (patch)
tree303147a136d45742de6e9887737aec8f5e97ee05 /ironicclient/common/filecache.py
parent1ad685d2eac72f7ac72281e13cf7d439a5b67002 (diff)
downloadpython-ironicclient-8c811afcab451cd2bced3776dac90228ef7fb565.tar.gz
Add env var for version cache timeout
As part of the Newton midcycle, it was discussed that it might be nice to be able to specify the version cache timeout value via an environment variable, rather than the current hard-coded value. Fixes-bug: #1596734 Change-Id: I2bc77c64b764f6c22574a30b0e5af4ca6feff29f
Diffstat (limited to 'ironicclient/common/filecache.py')
-rw-r--r--ironicclient/common/filecache.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/ironicclient/common/filecache.py b/ironicclient/common/filecache.py
index a3d39b8..f85a69c 100644
--- a/ironicclient/common/filecache.py
+++ b/ironicclient/common/filecache.py
@@ -14,18 +14,23 @@
# License for the specific language governing permissions and limitations
# under the License.
+import logging
import os
import appdirs
import dogpile.cache
+from ironicclient.common.i18n import _LW
+
+LOG = logging.getLogger(__name__)
AUTHOR = 'openstack'
PROGNAME = 'python-ironicclient'
+CACHE = None
CACHE_DIR = appdirs.user_cache_dir(PROGNAME, AUTHOR)
+CACHE_EXPIRY_ENV_VAR = 'IRONICCLIENT_CACHE_EXPIRY' # environment variable
CACHE_FILENAME = os.path.join(CACHE_DIR, 'ironic-api-version.dbm')
-CACHE = None
DEFAULT_EXPIRY = 300 # seconds
@@ -38,9 +43,22 @@ def _get_cache():
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
+ # Use the cache expiry if specified in an env var
+ expiry_time = os.environ.get(CACHE_EXPIRY_ENV_VAR, DEFAULT_EXPIRY)
+ try:
+ expiry_time = int(expiry_time)
+ except ValueError:
+ LOG.warning(_LW("Environment variable %(env_var)s should be an "
+ "integer (not '%(curr_val)s') using default "
+ "timeout of %(default)s instead"),
+ {'env_var': CACHE_EXPIRY_ENV_VAR,
+ 'curr_val': expiry_time,
+ 'default': DEFAULT_EXPIRY})
+ expiry_time = DEFAULT_EXPIRY
+
CACHE = dogpile.cache.make_region(key_mangler=str).configure(
'dogpile.cache.dbm',
- expiration_time=DEFAULT_EXPIRY,
+ expiration_time=expiry_time,
arguments={
"filename": CACHE_FILENAME,
}