示例#1
0
    def is_cache(self, gid, option):
        #check last requested timestamp
        #get last request timestamp and filter
        requested_str = self.rc.hget(S1.cache_key(gid),
                                     S1.cache_requested_key())
        last_filter = self.rc.hget(S1.cache_key(gid), S1.cache_filter_key())
        #save last request time and filter
        self.rc.hset(S1.cache_key(gid), S1.cache_requested_key(), time.time())
        self.rc.hset(S1.cache_key(gid), S1.cache_filter_key(), option)

        if requested_str:
            if (not last_filter or option == last_filter) and time.time(
            ) - float(requested_str) < config.DEFAULT_FORCE_MISS_TIMEOUT:
                self.logger.warning('Force-request detected [{0}]'.format(gid))
            else:
                # cache hit
                return True
        else:
            self.logger.warning('New user detected [{0}]'.format(gid))

        # cache miss
        return False
示例#2
0
    def check_orphan(self, gid, at_time):
        """ returns true if gid is orphaned """
        #get last requested timestamp
        requested_str = self.rc.hget(S1.cache_key(gid),
                                     S1.cache_requested_key())
        if not requested_str:
            return False

        # compare to orphaned timeout
        if at_time - float(requested_str) < config.DEFAULT_ORPHANED_TIMEOUT:
            return False

        return True
示例#3
0
 def reset_cache(self, gid):
     self.set_poll_stamp(gid, 0)
     self.rc.hset(S1.cache_key(gid), S1.cache_requested_key(), time.time())