mirror of
https://github.com/lilydjwg/nvchecker
synced 2024-12-29 10:02:09 +00:00
parent
db376ccfed
commit
aabf9f5037
@ -38,7 +38,18 @@ def substitute_version(version, name, conf):
|
||||
# No substitution rules found. Just return the original version string.
|
||||
return version
|
||||
|
||||
_cache = {}
|
||||
|
||||
async def get_version(name, conf, **kwargs):
|
||||
cache_key = tuple(sorted(conf.items()))
|
||||
if cache_key in _cache:
|
||||
return _cache[cache_key]
|
||||
|
||||
version = await _get_version_real(name, conf, **kwargs)
|
||||
_cache[cache_key] = version
|
||||
return version
|
||||
|
||||
async def _get_version_real(name, conf, **kwargs):
|
||||
for key in handler_precedence:
|
||||
if key in conf:
|
||||
func = import_module('.source.' + key, __package__).get_version
|
||||
|
12
tests/test_cache.py
Normal file
12
tests/test_cache.py
Normal file
@ -0,0 +1,12 @@
|
||||
# MIT licensed
|
||||
# Copyright (c) 2018 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
async def test_cache(get_version):
|
||||
a = await get_version("a", {"cmd": "date +%%N"})
|
||||
b = await get_version("b", {"cmd": "date +%%N"})
|
||||
c = await get_version("c", {"cmd": "date"})
|
||||
assert a == b
|
||||
assert a != c
|
Loading…
Reference in New Issue
Block a user