Пример #1
0
                cache.set(admin_list_key, admin_list)

            self.admin_list = admin_list
            self.admin_list_time = time.time()
            log.debug("Yay, got admin list %r, which we're hard caching until %r",
                admin_list, self.admin_list_time)

        return self.admin_list


### Cache support

if settings.FRONTEND_CACHING:
    from typepadapp.caching import cache_link, cache_object, invalidate_rule

    # Cache population/invalidation
    Group.get_by_url_id = cache_object(Group.get_by_url_id)
    # invalidate with: signals.group_webhook

    Group.events = cache_link(Group.events)
    group_events_invalidator = invalidate_rule(
        key=lambda sender, group=None, **kwargs: group and group.events,
        signals=[signals.asset_created, signals.asset_deleted],
        name="Group events invalidation for asset_created, asset_deleted signal")

    Group.memberships = cache_link(Group.memberships)
    memberships_invalidator = invalidate_rule(
        key=lambda sender, group=None, **kwargs: group and group.memberships,
        signals=[signals.member_banned, signals.member_unbanned, signals.member_joined, signals.member_left],
        name="group memberships for member_banned, member_unbanned, member_joined, member_left signals")
Пример #2
0

### Cache support

if settings.FRONTEND_CACHING:
    from typepadapp.caching import cache_link, cache_object, invalidate_rule

    # this is so we cache all Post, Video, Comment, etc., assets using
    # the same namespace.
    Asset.cache_namespace = "Asset"
    Favorite.cache_namespace = "Favorite"

    Asset.get_by_url_id = cache_object(Asset.get_by_url_id)
    asset_invalidator_for_comments = invalidate_rule(
        key=lambda sender, instance=None, **kwargs:
            isinstance(instance, Comment) and Asset.get_by_url_id(instance.in_reply_to.url_id),
        signals=[signals.asset_created, signals.asset_deleted],
        name="asset object invalidation for commenting")
    asset_invalidator_for_favorites = invalidate_rule(
        key=lambda sender, parent=None, **kwargs: parent,
        signals=[signals.favorite_created, signals.favorite_deleted],
        name="asset object invalidation for favoriting")

    Asset.comments = cache_link(Asset.comments)
    asset_comments_invalidator = invalidate_rule(
        key=lambda sender, instance=None, **kwargs:
            isinstance(instance, Comment) and Asset.get_by_url_id(instance.in_reply_to.url_id).comments,
        signals=[signals.asset_created, signals.asset_deleted],
        name="asset comments list invalidation for commenting")

    Asset.favorites = cache_link(Asset.favorites)
Пример #3
0
### Caching support

if settings.FRONTEND_CACHING:
    from typepadapp.caching import cache_link, cache_object, invalidate_rule
    from typepadapp import signals

    def make_user_alias_cache_key(self):
        """Attempts to use a caching key of the user's username, if available."""
        return "objectcache:%s:%s" % (self.cache_namespace, self.preferred_username or self.url_id)
    User.cache_key = property(make_user_alias_cache_key)
    UserProfile.cache_key = property(make_user_alias_cache_key)

    User.get_by_url_id = cache_object(User.get_by_url_id)
    user_invalidator = invalidate_rule(
        key=lambda sender, instance=None, group=None, **kwargs: instance,
        signals=[signals.member_banned, signals.member_unbanned],
        name="user cache invalidation for member_banned, member_unbanned signals")

    UserProfile.get_by_url_id = cache_object(UserProfile.get_by_url_id)
    user_profile_invalidator = invalidate_rule(
        key=lambda sender, instance=None, group=None, **kwargs: UserProfile.get_by_url_id(instance.preferred_username or instance.url_id),
        signals=[signals.member_banned, signals.member_unbanned],
        name="user profile cache invalidation for member_banned, member_unbanned signals")

    User.events = cache_link(User.events)
    user_events_invalidator = invalidate_rule(
        key=lambda sender, group=None, instance=None, **kwargs:
            instance and instance.author and group and [instance.author.notifications.filter(by_group=group),
                instance.author.preferred_username and User.get_by_url_id(instance.author.preferred_username).notifications.filter(by_group=group)],
        signals=[signals.asset_created, signals.asset_deleted],
        name="user notifications for group cache invalidation for asset_created, asset_deleted signals")