durusmail: quixote-users: Augmenting StaticFile to use "Expires:"
Augmenting StaticFile to use "Expires:"
2003-05-31
2003-05-31
2003-06-02
Jason Sibre (3 parts)
Re: Augmenting StaticFile to use "Expires:"
2003-06-21
2003-06-21
2003-06-23
Re: Augmenting StaticFile to use "Expires:"
2003-07-15
Augmenting StaticFile to use "Expires:"
Massa, Harald
2003-05-31
Jason,

very nice patch, really improving Cache-Performance!

I have to additions:

first: I would like the default to be -1, no Caching. So when swapping in
your util.py, working code does not get broken.

Second:

within

def _q_lookup(self, request, name):

there are two distinctions: files and directories. In your patch cache_time
is only passed on to files, not to directories.
So I suggest:

 def _q_lookup(self, request, name):
        """
        Get a file from the filesystem directory and return the StaticFile
        or StaticDirectory wrapper of it; use caching if that is in use.
        """
        if name in ('.', '..'):
            raise errors.TraversalError(private_msg="Attempt to use '.',
'..'")
        if self.cache.has_key(name):
            # Get item from cache
            item = self.cache[name]
        else:
            # Get item from filesystem; cache it if caching is in use.
            item_filepath = os.path.join(self.path, name)
            while os.path.islink(item_filepath):
                if not self.follow_symlinks:
                    raise errors.TraversalError
                else:
                    dest = os.readlink(item_filepath)
                    item_filepath = os.path.join(self.path, dest)

            if os.path.isdir(item_filepath):
                item = StaticDirectory(item_filepath, self.use_cache,
                        self.list_directory,
self.follow_symlinks,cache_time=self.cache_time) # !!! also propagate
cache-time to subdirectories
            elif os.path.isfile(item_filepath):
                item = StaticFile(item_filepath, self.follow_symlinks,
cache_time=self.cache_time)
            else:
                raise errors.TraversalError
            if self.use_cache:
                self.cache[name] = item
        if isinstance(item, StaticDirectory):
            return item
        else:
            return item(request)



Thank you very much for sharing this extension,

best wishes, Harald
reply