Esempio n. 1
0
class TickeryCache(service.Service):
    def __init__(self, cacheDir, restoreAddQueue, queueWidth, endpoint):
        self.cacheDir = cacheDir
        self.restoreAddQueue = restoreAddQueue
        self.queueWidth = queueWidth
        self.endpoint = endpoint
        # oauthTokenDict is a volatile cache.
        self.oauthTokenDict = {}
        self.extraTwitterTagsPool = DeferredPool()

    def startService(self):
        self.loadAllCaches()

    def loadAllCaches(self):
        service.Service.startService(self)

        cacheFile = functools.partial(os.path.join, self.cacheDir)

        self.userCache = TwitterUserCache()
        self.userCache.load(cacheFile("users"))

        self.oidUidScreennameCache = OidUidScreennameCache(self.endpoint)
        self.oidUidScreennameCache.load(cacheFile("oidUidScreenname"))

        self.queryCache = QueryCache()
        self.queryCache.load(cacheFile("queries"))

        self.cookieCache = CookieCache()
        self.cookieCache.load(cacheFile("cookies"))

        self.adderCache = AdderCache(self, self.queueWidth, self.endpoint)
        self.adderCache.load(cacheFile("adder"))

        self.friendsIdCache = FriendsCache()
        self.friendsIdCache.load(cacheFile("friends"))

    @defer.inlineCallbacks
    def stopService(self):
        yield self.adderCache.close()
        yield self.extraTwitterTagsPool.notifyWhenEmpty()
        self.userCache.close()
        self.oidUidScreennameCache.close()
        self.queryCache.close()
        self.cookieCache.close()
        self.friendsIdCache.close()
        service.Service.stopService(self)
Esempio n. 2
0
    def loadAllCaches(self):
        service.Service.startService(self)

        cacheFile = functools.partial(os.path.join, self.cacheDir)

        self.userCache = TwitterUserCache()
        self.userCache.load(cacheFile("users"))

        self.oidUidScreennameCache = OidUidScreennameCache(self.endpoint)
        self.oidUidScreennameCache.load(cacheFile("oidUidScreenname"))

        self.queryCache = QueryCache()
        self.queryCache.load(cacheFile("queries"))

        self.cookieCache = CookieCache()
        self.cookieCache.load(cacheFile("cookies"))

        self.adderCache = AdderCache(self, self.queueWidth, self.endpoint)
        self.adderCache.load(cacheFile("adder"))

        self.friendsIdCache = FriendsCache()
        self.friendsIdCache.load(cacheFile("friends"))