[Seaside] File downloads etc
goran at krampe.se
goran at krampe.se
Tue Jan 10 09:43:34 CET 2006
Avi Bryant <avi.bryant at gmail.com> wrote:
> On Jan 10, 2006, at 12:13 AM, goran at krampe.se wrote:
> > Anyway, suppose we add these two methods to WAImageTag:
> > WAImageTag>>fileName: aFileName mimeType: mimeString
> > "Create a document handler for the file contents and insert
> > a URL for it. The document will be served binary and with
> > a non expiring cache."
> > ^self url: (canvas context
> > urlForDocument: ((StandardFileStream readOnlyFileNamed: aFileName)
> > binary; contentsOfEntireFile)
> > mimeType: mimeString
> > fileName: aFileName).
> Hm, well, the problem with doing that is that although you're caching
> the contents in the image, you're also reading the file from disk
> every time, which does seem awfully wasteful. The right thing to do
Eh... oh. Right, I am! :) Kinda got lost in the code and thought it
would get cached (since the year 2095 expiry thing) but of course, the
*above* code is run each time. Duh.
> here is to add a level of abstraction and create a new document
> class. What #urlForDocument: is expecting is something with the
> following two properties:
> - it responds reasonably to #asMIMEDocument
> - it has a reasonable implementation of #= (most likely, it is #= to
> other things that produce the identical mime document)
> Beyond that, you can be as smart as you like. So, I would do
> something like:
> - Create a FileDocument class that holds onto the file name or path
> - Two FileDocuments with the same path are #=
> - #asMIMEDocument reads in the file stream on demand. It may cache
> it, with whatever caching policy seems reasonable, check the mtime of
> the file etc.
> For bonus points, have #= take the mtime of the cached version into
> account so that two FileDocuments are *not* equal if their mtimes
> differ; this means a new URL will be generated every time the file on
> disk changes and so clients will immediately get the updated content.
Mmm. Sounds reasonable yes. Ok, I will give it a shot.
More information about the Seaside