~jeffpc/libjeffpc#33: 
file cache: conditionally cache file contents

Right now, the event ports implementation caches both "has this file changed" information as well as the file contents. The generic fallback doesn't cache anything.

Ultimately, there are two levels of caching:

  1. file "generation"
  2. file "generation" and file contents

In some cases, it makes sense to cache the contents as well. For example, blahgd's template files are small, read-mostly, and the consumer doesn't do any of its own caching.

In other cases, it doesn't make sense to cache the contents. For example, blahgd's post files take a non-trivial amount of time to parse, and blahgd caches the html it generates from them anyway. If the file cache indicates that the files haven't changed, blahgd just uses its own cached string.

So, it is reasonable to extend the file_cache_get function to take a flags argument to indicate whether the read in data should be cached. That is:

if (!changed && cached)
        return cached-data;

cached-data = NULL;
data = read();
if (flags & FILE_CACHE_IN_MEMORY)
        cached-data = data;
return data;
Status
REPORTED
Submitter
~jeffpc
Assigned to
No-one
Submitted
9 months ago
Updated
9 months ago
Labels
feature