Beispiel #1
0
 def cache_info(self):
     """
     get all cache info
     """
     cache_info = {}
     for cache_obj, cache_name, cache_type in SpuCacheManager._c_cache:
         _cache = {}
         if cache_obj:
             access = cache_obj.access() + 2
             hit = cache_obj.hit() + 1
             miss = cache_obj.miss() + 1
             hit_rate = '%s%%' % round(float(hit) / float(access) * 100, 2)
             miss_rate = '%s%%' % round(
                 float(miss) / float(access) * 100, 2)
             _cache['enable'] = True
             _cache['cache_size'] = cache_obj.cache_size()
             _cache['access'] = access
             _cache['hit'] = hit
             _cache['miss'] = miss
             _cache['hit_rate'] = hit_rate
             _cache['miss_rate'] = miss_rate
         else:
             _cache['enable'] = False
         cache_info[cache_name] = _cache
     result = {'cache_info': cache_info}
     return self._response(Pyobject(success, result))
Beispiel #2
0
 def all(self):
     result = {
         'version': self.__version(),
         'process_start_time': self.__process_start_time(),
         'process_run_time': self.__process_run_time()
     }
     return self._response(Pyobject(success, result))
Beispiel #3
0
 def ioloop_info(self):
     """
     get ioloop info
     """
     ioloop_info = self.__get_ioloop_info()
     return self._response(
         Pyobject(
             success, {
                 'status': 'ok',
                 'socket_count': len(ioloop_info),
                 'ioloop_info': ioloop_info
             }))
Beispiel #4
0
 def process_cache_original_keys(self,
                                 key_rule={
                                     'atype': str,
                                     'aneed': True
                                 }):
     """
     """
     for cache_obj, _, cache_type in SpuCacheManager._c_cache:
         if cache_obj and cache_type == SpuCacheManager.ProcessCache:
             result = cache_obj.original_keys(key_rule)
             return self._response(PyobjectList(success, result))
     return self._response(Pyobject(cache_type_error, None))
Beispiel #5
0
 def cache_action(self,
                  cache_type={
                      'atype': str,
                      'aneed': True
                  },
                  action={
                      'atype': str,
                      'aneed': True
                  },
                  **kwargs):
     """
     run cache action
     action list:
       set_value(self, key, value, expire=0)
       get_value(self, key)
       remove(self, key)
       keys(self, key_rule)
       cache_size(self)
       get_all(self)
       expire(self, key, expire_time)
       ttl(self, key)
     """
     result = None
     if 'expire' in kwargs:
         kwargs['expire'] = int(kwargs['expire'])
     if 'expire_time' in kwargs:
         kwargs['expire_time'] = int(kwargs['expire_time'])
     for cache_obj, cache_name, _ in SpuCacheManager._c_cache:
         if cache_obj and cache_name == cache_type:
             if hasattr(cache_obj, action):
                 result = getattr(cache_obj, action)(**kwargs)
                 result = self.__process_get(action, result)
                 return self._response(PyobjectList(success, result))
             else:
                 return self._response(Pyobject(action_error, None))
     return self._response(Pyobject(cache_type_error, None))
Beispiel #6
0
 def process_run_time(self):
     return self._response(Pyobject(success, self.__process_run_time()))
Beispiel #7
0
 def version(self):
     return self._response(Pyobject(success, self.__version()))
Beispiel #8
0
 def ping(self):
     tid = thread.get_ident()
     return self._response(Pyobject(success, {'status': 'ok', 'tid': tid}))