Beispiel #1
0
    def is_local_asset(self):
        return self.object and isinstance(self.object, Asset) \
            and self.object.is_local


### 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],
Beispiel #2
0
import httplib2
from urlparse import urljoin

from django.core.cache import cache
from django.conf import settings
from typepadapp.models.assets import Event, Post, Comment
from typepadapp import signals
import typepad

log = logging.getLogger(__name__)


class Blog(typepad.Blog):
    pass



class AnonymousComment(Comment):
    name = typepad.fields.Field()
    email = typepad.fields.Field()

    
### Cache support
### TODO: implement cache invalidation
if settings.FRONTEND_CACHING:
    from typepadapp.caching import cache_link, cache_object, invalidate_rule

    # Cache population/invalidation
    Blog.get_by_url_id = cache_object(Blog.get_by_url_id)

    # invalidation not yet implemented!
Beispiel #3
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")
Beispiel #4
0
        return User.get_by_id(self.id).get_profile()


### 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),