cache_helper.py 478 B

1234567891011121314151617
  1. # -*- coding: utf-8 -*-
  2. class CacheHelper(object):
  3. def __init__(self, env):
  4. self.dic = {}
  5. self.env = env
  6. def safe_get(self, key, value_if_empty=u'-无-'):
  7. if not key:
  8. return value_if_empty
  9. if key not in self.dic:
  10. result = self.env.search_read([('id', '=', key)], ['name'], limit=1)
  11. name = result[0]['name'] if result else u'-已删除-'
  12. self.dic[key] = name
  13. return self.dic[key]