def get_memcache(self, memcache_servers): global _memcache if _memcache is None: from openlibrary.utils import olmemcache _memcache = olmemcache.Client(memcache_servers) return _memcache
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()
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()
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()
def get_memcache(): """Returns memcache client created from infobase configuration. """ cache = config.get("cache", {}) if cache.get("type") == "memcache": return olmemcache.Client(cache['servers'])
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)
def get_memcache(): global _memcache if _memcache is None and config.get("ol_memcache_servers"): _memcache = olmemcache.Client(config.ol_memcache_servers) return _memcache