Exemplo n.º 1
0
    def get_memcache(self, memcache_servers):
        global _memcache
        if _memcache is None:
            from openlibrary.utils import olmemcache

            _memcache = olmemcache.Client(memcache_servers)
        return _memcache
Exemplo n.º 2
0
def main():
    m = olmemcache.Client(["ia331532:7060", "ia331533:7060"])
    db = web.database(dbn="postgres",
                      db="openlibrary",
                      user="******",
                      pw="",
                      host="ia331526")

    t = db.transaction()
    try:
        db.query(
            "DECLARE datacur CURSOR FOR SELECT thing.key, data.data FROM thing, data WHERE thing.id=data.thing_id and data.revision=thing.latest_revision ORDER BY thing.id"
        )
        limit = 10000
        i = 0
        while True:
            i += 1
            result = db.query('FETCH FORWARD $limit FROM datacur',
                              vars=locals()).list()
            if not result:
                break
            t1 = time.time()
            d = dict((r.key, r.data) for r in result)
            try:
                m.set_multi(d)
                #m.add_multi(d)
            except:
                m.delete_multi(d.keys())
                print >> web.debug, 'failed to add to memcached', repr(r.key)

            t2 = time.time()
            print >> web.debug, "%.3f" % (t2 -
                                          t1), i, "adding memcache records"
    finally:
        t.rollback()
Exemplo n.º 3
0
 def memcache(self):
     servers = config.get("memcache_servers", None)
     if servers:
         return olmemcache.Client(servers)
     else:
         web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.")
         import mockcache
         return mockcache.Client()
Exemplo n.º 4
0
 def memcache(self):
     servers = config.get("memcache_servers", None)
     if servers:
         return olmemcache.Client(servers)
     else:
         web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.")
         try:
             import mockcache
             return mockcache.Client()
         except ImportError:
             from pymemcache.test.utils import MockMemcacheClient
             return MockMemcacheClient()
Exemplo n.º 5
0
def get_memcache():
    """Returns memcache client created from infobase configuration.
    """
    cache = config.get("cache", {})
    if cache.get("type") == "memcache":
        return olmemcache.Client(cache['servers'])
Exemplo n.º 6
0
def setup_memcache(servers):
    """Setup the memcached servers. 
    This must be called along with setup_database, if memcached servers are used in the system.
    """
    global mc
    mc = olmemcache.Client(servers)
Exemplo n.º 7
0
def get_memcache():
    global _memcache
    if _memcache is None and config.get("ol_memcache_servers"):
        _memcache = olmemcache.Client(config.ol_memcache_servers)
    return _memcache