django-cacheback icon indicating copy to clipboard operation
django-cacheback copied to clipboard

Cacheback templatetag

Open mitchelljkotler opened this issue 8 years ago • 3 comments

I would like a general purpose cacheback template tag that functions the same as the builtin cache template tag except uses cacheback to update the cache asynchronously. I started a branch to implement such a tag, but there is a major problem of serializing the context to send to celery to process. I cannot get it to serialize with cPickle at all and with regular pickle it took ~30 seconds which is clearly unacceptable and would require some sort of custom serializer to use pickle instead of cPickle. Does anybody have any ideas how we can serialize the request context to celery in a reasonable amount of time?

mitchelljkotler avatar Dec 18 '16 01:12 mitchelljkotler

I'm not sure if passing serializing the whole context can be done easily or fast enough.

stephrdev avatar Dec 20 '16 18:12 stephrdev

I agree - I am currently working on an implementation that passes just the original environment (which is easily serializable) to celery, which then triggers an entire page re-render in order to update the cache with the new values. This is obviously tricky and has potential to not play nicely with other apps, and can only be done for GET requests.

I was also thinking about an implementation where you also pass in the context keys that need to be copied (or try to derive it automatically from the template parser) and only serialize that part of the context. I haven't tried this approach yet.

mitchelljkotler avatar Dec 20 '16 18:12 mitchelljkotler

Sounds complex to me. Feel free to build an proof of concept but I'm really not sure if this should land in cacheback. Maybe an extra library built up on cacheback?

stephrdev avatar Dec 20 '16 19:12 stephrdev