File caching made (not so) simple
I wanted my Digital Signage solution to be less vulnerable to network losses (and save some bandwidth). As the client exists as a flex-version for browser preview and a AIR runtime version on the Panels, i had to come up with a solution providing a minimalistic interface with minimal code changes needed. So a event-based caching mechanism (doing a lookup and providing the asset on an event) was a nogo.
The solution was, to get all URLRequests be checked against the local cache at load time. If the url is cached, the file-url is returned instead. If not, the original url is returned, but also queued for downloading and caching after the original url has been retrieved (being triggered by a COMPLETE and relying on the browser/runtime cache for further speedup).
To optimize this scheme, i thought of conditional get’s fired even after cached url-requests, to keep the cache up to date. Finally i used a SQLite database in synchronous mode to store the servers ETag and Last-Modified values along the url and filename (which is a MD5 of the url and the delivered ETag).
This all sounds a bit confusing, but i wanted this write it down immediately and get it revised afterwards.
Leave a Reply