コード例 #1
0
def _process_collection_event(memcached_client, event_data):
    log = logging.getLogger("_process_collection_event")
    if event_data["event"] != "UPDATE":
        log.error("unknown event {0}".format(event_data))
        return

    lookup_fields = [
        "id",
        "name",
    ]
    for lookup_field in lookup_fields:
        key = memcached_central_key_template.format(
            "collection", lookup_field, event_data["old"][lookup_field])
        result = memcached_client.delete(key)
        log.info("delete {0} result = {1}".format(key, result))

    # deleted collections have their name changed to have __deleted__$id__ at
    # the front so that they do not conflict with future collections.  in order
    # to clear caches even when we have mass updates.
    name = event_data['old']['name']
    if name.startswith("__deleted__"):
        undecorated_name = name[name.rindex("_") + 1:]
        key = memcached_central_key_template.format("collection", "name",
                                                    undecorated_name)
        result = memcached_client.delete(key)
        log.info("delete {0} result = {1}".format(key, result))
コード例 #2
0
def _process_collection_event(memcached_client, event_data):
    log = logging.getLogger("_process_collection_event")
    if event_data["event"] != "UPDATE":
        log.error("unknown event {0}".format(event_data))
        return

    lookup_fields = ["id", "name", ]
    for lookup_field in lookup_fields:
        key = memcached_central_key_template.format(
            "collection", 
            lookup_field, 
            event_data["old"][lookup_field])
        result = memcached_client.delete(key)
        log.info("delete {0} result = {1}".format(key, result))

    # deleted collections have their name changed to have __deleted__$id__ at
    # the front so that they do not conflict with future collections.  in order
    # to clear caches even when we have mass updates.
    name = event_data['old']['name']
    if name.startswith("__deleted__"):
        undecorated_name = name[name.rindex("_") + 1:]
        key = memcached_central_key_template.format(
            "collection", "name", undecorated_name)
        result = memcached_client.delete(key)
        log.info("delete {0} result = {1}".format(key, result))
コード例 #3
0
    def get(self, lookup_field_value):
        """
        retrieve a dict of column data from memcached, or database
        return None if not found
        """
        memcached_key = \
            memcached_central_key_template.format(self._table_name,
                                                  self._lookup_field_name,
                                                  lookup_field_value)

        cached_dict = self._memcached_client.get(memcached_key)
        if cached_dict is not None:
            self._log.debug("cache hit {0}".format(memcached_key))
            return cached_dict

        # cache miss, try the database
        self._log.debug("cache miss {0}".format(memcached_key))
        database_dict = self._database_lookup_function(lookup_field_value)

        if database_dict is not None:
            self._log.debug("database hit {0}".format(memcached_key))
            success = \
                self._memcached_client.set(memcached_key, 
                                           database_dict, 
                                           time=_expiration_time_in_seconds)
            if not success:
                self._log.error(
                    "self._memcached_client.set({0}...) returned {1}".format(
                        memcached_key, success))

        if database_dict is None:
            self._log.debug("database miss {0}".format(memcached_key))

        return database_dict
コード例 #4
0
def _process_customer_key_event(memcached_client, event_data):
    log = logging.getLogger("_process_customer_key_event")
    if event_data["event"] != "UPDATE":
        log.error("unknown event {0}".format(event_data))
        return

    lookup_field = "id"
    key = memcached_central_key_template.format(
        "customer_key", lookup_field, event_data["old"][lookup_field])
    result = memcached_client.delete(key)
    log.info("delete {0} result = {1}".format(key, result))
コード例 #5
0
def _process_customer_key_event(memcached_client, event_data):
    log = logging.getLogger("_process_customer_key_event")
    if event_data["event"] != "UPDATE":
        log.error("unknown event {0}".format(event_data))
        return

    lookup_field = "id"
    key = memcached_central_key_template.format(
        "customer_key", 
        lookup_field, 
        event_data["old"][lookup_field])
    result = memcached_client.delete(key)
    log.info("delete {0} result = {1}".format(key, result))