示例#1
0
    def __call__(self, environ, start_response):

        # Make sure request-cached values are cleared at start of request
        flush_request_cache()
        flush_identity_cache()

        def gae_bingo_start_response(status, headers, exc_info=None):

            if using_logged_in_bingo_identity():
                if get_identity_cookie_value():
                    # If using logged in identity, clear cookie b/c we don't need it
                    # and it can cause issues after logging out.
                    headers.append(("Set-Cookie", delete_identity_cookie_header()))
            else:
                # Not using logged-in identity. If current identity isn't already stored in cookie,
                # do it now.
                if identity() != get_identity_cookie_value():
                    headers.append(("Set-Cookie", set_identity_cookie_header()))

            return start_response(status, headers, exc_info)

        result = self.app(environ, gae_bingo_start_response)
        for value in result:
            yield value

        # Persist any changed GAEBingo data to memcache
        store_if_dirty()

        # We probably don't need to do this b/c we clear the cache at the start of each request,
        # but what the heck, cache bugs are just the worst.
        flush_request_cache()
        flush_identity_cache()
示例#2
0
    def __call__(self, environ, start_response):

        try:
            # Make sure request-cached values are cleared at start of request
            request_cache.flush_request_cache()

            def gae_bingo_start_response(status, headers, exc_info = None):

                if identity.using_logged_in_bingo_identity():
                    if identity.get_identity_cookie_value():
                        # If using logged in identity, clear cookie b/c we don't need it
                        # and it can cause issues after logging out.
                        headers.append(("Set-Cookie",
                                        identity.delete_identity_cookie_header()))
                else:
                    # Not using logged-in identity. If current identity isn't
                    # already stored in cookie, do it now.
                    if identity.identity() != identity.get_identity_cookie_value():
                        headers.append(("Set-Cookie",
                                        identity.set_identity_cookie_header()))

                return start_response(status, headers, exc_info)

            result = self.app(environ, gae_bingo_start_response)
            for value in result:
                yield value

            # Persist any changed GAEBingo data to memcache
            cache.store_if_dirty()

            # If we got a new ID, we should put it to the datastore so it persists
            identity.put_id_if_necessary()

        finally:
            request_cache.flush_request_cache()
示例#3
0
    def __call__(self, environ, start_response):

        # Make sure request-cached values are cleared at start of request
        flush_request_cache()
        flush_identity_cache()

        def gae_bingo_start_response(status, headers, exc_info=None):

            if using_logged_in_bingo_identity():
                if get_identity_cookie_value():
                    # If using logged in identity, clear cookie b/c we don't need it
                    # and it can cause issues after logging out.
                    headers.append(
                        ("Set-Cookie", delete_identity_cookie_header()))
            else:
                # Not using logged-in identity. If current identity isn't already stored in cookie,
                # do it now.
                if identity() != get_identity_cookie_value():
                    headers.append(
                        ("Set-Cookie", set_identity_cookie_header()))

            return start_response(status, headers, exc_info)

        result = self.app(environ, gae_bingo_start_response)
        for value in result:
            yield value

        # Persist any changed GAEBingo data to memcache
        store_if_dirty()

        # We probably don't need to do this b/c we clear the cache at the start of each request,
        # but what the heck, cache bugs are just the worst.
        flush_request_cache()
        flush_identity_cache()
示例#4
0
 def __exit__(self, exc_type, exc_value, traceback):
     # Forcefully flush the cache, since this must be done inside of
     # the monitor. The mutation methods (e.g. choose_alternative) are
     # implemented in such a way that they rely on the gae/bingo middleware
     # to flush the data. But by that point the lock will have been released
     cache.store_if_dirty()
     ExperimentController._lock_set = False
     logging.info("Exiting monitor from ExperimentController. About to "
                  "release the lock (current value: [%s])" %
                  self.lock.is_active())
     self.lock.release()
示例#5
0
 def __exit__(self, exc_type, exc_value, traceback):
     # Forcefully flush the cache, since this must be done inside of
     # the monitor. The mutation methods (e.g. choose_alternative) are
     # implemented in such a way that they rely on the gae/bingo middleware
     # to flush the data. But by that point the lock will have been released
     cache.store_if_dirty()
     ExperimentController._lock_set = False
     logging.info(
             "Exiting monitor from ExperimentController. About to "
             "release the lock (current value: [%s])" %
             self.lock.is_active())
     self.lock.release()
示例#6
0
    def __call__(self, environ, start_response):

        try:
            # Make sure request-cached values are cleared at start of request
            request_cache.flush_request_cache()

            def gae_bingo_start_response(status, headers, exc_info=None):

                if identity.using_logged_in_bingo_identity():
                    if identity.get_identity_cookie_value():
                        # If using logged in identity, clear cookie b/c we don't need it
                        # and it can cause issues after logging out.
                        headers.append(
                            ("Set-Cookie",
                             identity.delete_identity_cookie_header()))
                else:
                    # Not using logged-in identity. If current identity isn't
                    # already stored in cookie, do it now.
                    if identity.identity(
                    ) != identity.get_identity_cookie_value():
                        headers.append(("Set-Cookie",
                                        identity.set_identity_cookie_header()))

                return start_response(status, headers, exc_info)

            result = self.app(environ, gae_bingo_start_response)
            for value in result:
                yield value

            # Persist any changed GAEBingo data to memcache
            cache.store_if_dirty()

            # If we got a new ID, we should put it to the datastore so it persists
            identity.put_id_if_necessary()

        finally:
            request_cache.flush_request_cache()