From eb24faa27cb748ebb10226d81dd300c65e3fa610 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 03 2015 01:24:30 +0000 Subject: Implement invalidation and rebuilding. --- diff --git a/hubs/consumer.py b/hubs/consumer.py index 0f36f63..08d1eca 100644 --- a/hubs/consumer.py +++ b/hubs/consumer.py @@ -7,6 +7,8 @@ import fedmsg.consumers import hubs.models +from hubs.widgets.base import invalidate_cache + import logging log = logging.getLogger("hubs") @@ -65,8 +67,12 @@ class CacheInvalidatorExtraordinaire(fedmsg.consumers.FedmsgConsumer): # And do the real work of comparing every widget against the message. for widget in widgets: if widget.module.should_invalidate(msg, session, widget): - raise NotImplementedError("Invalidate the cache...") - raise NotImplementedError("Rebuild it.") + log.info("Invalidating cache for %r" % widget) + # Invalidate the cache... + invalidate_cache(widget.module, **widget.config) + # Rebuild it. + widget.module.data(session, widget, **widget.config) + # TODO -- fire off an EventSource notice that we updated stuff log.info("Done. %0.2fs %s %s", time.time() - start, msg['msg_id'], msg['topic']) diff --git a/hubs/widgets/base.py b/hubs/widgets/base.py index f26edd6..e0d1581 100644 --- a/hubs/widgets/base.py +++ b/hubs/widgets/base.py @@ -60,6 +60,11 @@ def smartcache(module): return decorator +def invalidate_cache(module, *args, **kwargs): + key = cache_key_generator(module, *args, **kwargs) + cache.delete(key) + + def cache_key_generator(module, args, kwargs): return "|".join([ module.__name__,