feat: respect module_cache config for pricing cache
This commit is contained in:
parent
c041c76c9f
commit
8159c79d55
@ -6,9 +6,22 @@ from sqlor.dbpools import DBPools, get_sor_context
|
|||||||
from appPublic.log import debug, exception, info, MyLogger
|
from appPublic.log import debug, exception, info, MyLogger
|
||||||
from appPublic.timeUtils import curDateString
|
from appPublic.timeUtils import curDateString
|
||||||
from appPublic.dictObject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
from .write_pattern import write_pattern_xlsx, load_xlsx_pricing
|
from .write_pattern import write_pattern_xlsx, load_xlsx_pricing
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def _cache_enabled():
|
||||||
|
"""Check if cache is enabled for pricing module in config.json"""
|
||||||
|
try:
|
||||||
|
config = getConfig()
|
||||||
|
module_cache = config.module_cache
|
||||||
|
if module_cache is None:
|
||||||
|
return True
|
||||||
|
return getattr(module_cache, 'pricing', True)
|
||||||
|
except Exception:
|
||||||
|
return True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
采用yaml描述定价策略,
|
采用yaml描述定价策略,
|
||||||
在pricing_program的pricing_spec表中定义定价的数据字段
|
在pricing_program的pricing_spec表中定义定价的数据字段
|
||||||
@ -424,6 +437,7 @@ class PricingProgram:
|
|||||||
async def get_ppid_pricing(ppid):
|
async def get_ppid_pricing(ppid):
|
||||||
dat = curDateString()
|
dat = curDateString()
|
||||||
k = f'{ppid}.{dat}'
|
k = f'{ppid}.{dat}'
|
||||||
|
if _cache_enabled():
|
||||||
d = PricingProgram.pricing_data.get(k)
|
d = PricingProgram.pricing_data.get(k)
|
||||||
if d:
|
if d:
|
||||||
return d
|
return d
|
||||||
@ -446,6 +460,7 @@ class PricingProgram:
|
|||||||
exception(f'{e}')
|
exception(f'{e}')
|
||||||
raise e
|
raise e
|
||||||
d = recs[0]
|
d = recs[0]
|
||||||
|
if _cache_enabled():
|
||||||
PricingProgram.pricing_data[k] = d
|
PricingProgram.pricing_data[k] = d
|
||||||
dates = PricingProgram.pricing_data.get(ppid, [])
|
dates = PricingProgram.pricing_data.get(ppid, [])
|
||||||
dates.append(dat)
|
dates.append(dat)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user