Ejemplo n.º 1
0
    def flush_model(self, model, *extra):
        if SystemStatus.cache_server_down():
            return
        table = model.__storm_table__
        model_cls = model.__class__
        tables = utils.table_name(model_cls.get_cache_keys())
        relation_tables = utils.tables_key(tables)
        need_remove_keys = self._cache.get_multi(relation_tables) or []

        if need_remove_keys:
            final_keys = []
            for table_key, rel_key_list in need_remove_keys.iteritems():
                final_keys.append(table_key)
                for rel_key in rel_key_list:
                    final_keys.append(rel_key)

            app_log.debug("invalidate model cache %s with keys %s " %
                          (table, str(final_keys)))
            self._cache.delete_multi(final_keys)
Ejemplo n.º 2
0
    def _cache(*args, **kwargs):
        if SystemStatus.cache_server_down():
            app_log.error("cache server down, using database query directly")
            return func(*args, **kwargs)

        model = args[0]
        get_cache_func = model.get_all_from_cache
        cache_func = model.cache_all
        if func.__name__ == "paging":
            get_cache_func = model.get_paging_from_cache
            cache_func = model.cache_paging
        elif func.__name__ == "filter_by":
            get_cache_func = model.get_filter_by_from_cache
            cache_func = model.cache_filter_by

        cached_result = get_cache_func(func.__name__, args, kwargs)
        if cached_result:
            return cached_result
        else:
            db_result = func(*args, **kwargs)
            if db_result:
                cache_func(func.__name__, args, kwargs, db_result)
            return db_result
Ejemplo n.º 3
0
 def cacheserver_up(self, data):
     SystemStatus.set_cache_server_status(constant.CACHE_SERVER_UP)
     app_log.error("Cache Server was UP")
Ejemplo n.º 4
0
 def cacheserver_down(self, data):
     if SystemStatus.cache_server_up():
         app_log.error("Cache Server was Down!!!")
         SystemStatus.set_cache_server_status(constant.CACHE_SERVER_DOWN)
         context["executor"].submit(self._check_cache_state)
Ejemplo n.º 5
0
def set_service_status():
    from constant import CACHE_SERVER_UP, DATABASE_SERVER_UP
    from core import SystemStatus
    SystemStatus.set_cache_server_status(CACHE_SERVER_UP)
    SystemStatus.set_database_server_status(DATABASE_SERVER_UP)