So i have read the Django-Docs about caching and understood i can cache data per view which is what i want to do. I have a URL like this : www.mysite.com/related_images/{image_id}. which calculates related images for the selected {image_id} and saves them to the disk so they can be accessed by the template. Thing is i don't want those images to stay there forever, but right now my view saves them to the disk without any caching, how can i make sure that by caching the view for a certain period of time, any files created by the view will be deleted when the cache expires ?.
Or if you have a better solution for my problem, I'm open for ideas. Is there a way to inject images from cache into templates without saving them on disk and providing a path for the html explicitly ?
here's a simplified version of the view:
def related_image(request, pk):
original = get_object_or_404(Image, pk=pk)
images = original.get_previous_views()
for im in images:
path = '/some/dir/'+str(im.id)+'.jpg'
calculated_image = calculate(im,original)
file = open(path)
file.write(calculated_image)
im.file_path = path
return render_to_response('app/related_image.html', {'images': images})
Thanks :)