예제 #1
0
class SearchCache(object):
    def __init__(self):
        self.size = 10240
        self.timeout = 6    #600
        self.changedTime = time.time()
        self.cache = LRUCache(self.size)
    def data_changed(self):
        self.changedTime = time.time()
    def get_cache(self,k):
        if self.cache == None:
            return None
        if k in self.cache:
            m = self.changedTime - self.cache.mtime(k)
            #当缓存更新时间 - 更新时间 超过10分钟 则删除缓存
            if m > self.timeout:
                del self.cache[k]
                #logger.info('del cache:'+k+'==>'+m)
                return None
            else:
                logger.info("search get_cache:%s" %mkey)
                return self.cache[k]
        else:
            return None
    def add_cache(self,k,rep):
        if self.cache == None:
            return None
        self.cache[k] = rep
        logger.info("search add_cache:%s" %mkey)
    def del_cache(self):
        self.cache = LRUCache(self.size)
        logger.info('cache size :%d' %len(self.cache))
예제 #2
0
 def __init__(self, indexdir):
     exists = index.exists_in(indexdir)
     if exists:
         self.ix = index.open_dir(indexdir)
     else:
         schema = Schema(title=TEXT(stored=True),
                         id=NUMERIC(unique=True, stored=True),
                         orgid=NUMERIC(stored=True),
                         ishunterjob=NUMERIC(stored=True),
                         tags=KEYWORD(stored=True))
         self.ix = create_in(indexdir, schema)
     self.mac_address = self.get_mac_address()
     self.conn = pymongo.Connection(config.MONGO_CONN)
     self.tagsParser = Trie(config.SKILL_FILE)
     self.cache = LRUCache(1024)
예제 #3
0
 def del_cache(self):
     self.cache = LRUCache(self.size)
     logger.info('cache size :%d' %len(self.cache))
예제 #4
0
 def __init__(self):
     self.size = 10240
     self.timeout = 6    #600
     self.changedTime = time.time()
     self.cache = LRUCache(self.size)