0

I'm using django-tastypie to make resources for models.

Can you help tell me how to cache dehydrate method of my ArtistResource? And what extra django settings should i provide to use cache?

Thanks very much. I've never used cache before, so i'm discouraged about this.

class ArtistResource(DehydrateImageMixin, SearchableResource):
    class Meta:        
        filtering = {
            "id": ALL_WITH_RELATIONS,
        }
        queryset = Artist.objects.all()
        resource_name = 'artist'
        allowed_methods = ['get']

    def dehydrate(self, bundle):
        bundle = super(ArtistResource, self).dehydrate(bundle)
        count_tracks = bundle.obj.audio_tracks.count()
        bundle.data['count_tracks'] = ungettext(
            '%(count)d %(track)s', '%(count)d %(track)s', count_tracks
        ) % {'count': count_tracks, 'track': 'track'}
        return bundle
Feanor
  • 3,568
  • 5
  • 29
  • 49

1 Answers1

1

please refer this documentaion .this very clear

http://django-tastypie.readthedocs.org/en/latest/caching.html

just add

cache = SimpleCache(timeout=10) to your meta makes cache..

sundar nataraj
  • 8,524
  • 2
  • 34
  • 46
  • simple cache is only suitable for dev environment. Can i cache my methods with decorator and what keys should i use? – Feanor Feb 21 '13 at 22:35