Esempio n. 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")
Esempio n. 2
0
    # 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)
    # cache invalidation for asset object cache when a favorite is created/deleted
    asset_favorites_invalidator = invalidate_rule(
        key=lambda sender, parent=None, **kwargs: parent and parent.favorites,
        signals=[signals.favorite_created, signals.favorite_deleted],
        name="asset favorite list invalidation for favoriting")
Esempio n. 3
0
    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")

    User.notifications = cache_link(User.notifications)
    # signals.asset_created, signals.asset_deleted

    # We can't effectively signal to invalidate these lists because
    # follow/unfollow actions happen on typepad
    User.memberships = cache_link(User.memberships)
    user_memberships_invalidator = invalidate_rule(
        key=lambda sender, instance=None, group=None, **kwargs: