Feature: cache #3
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: stephenseo/c_simple_http#3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This can be implemented by doing the following:
It may be best to have a
--enable-cache-dir=<DIR>
to do both enabling of the cache and setting up a designated cache dir at the same time.It needs to be decided the name-format of cached html.
Perhaps also keep track of how old a cache file is, so that they are purged after a certain time period. Maybe a day to a week?
Could be set with
--cache-lifetime=<TIME>
. Will need to define a format for the time. Maybe "#d" for days and "#w" for weeks.Thinking about it, it probably would be best to modify the function that parses and constructs the html to also return the list of files used in the process.
char *c_simple_http_path_to_generated(
This function also uses something that may benefit to be separated into its own file: concatenating a string via the use of a linked-list and combining the linked-list items into a single buffer. I would probably do this first as it may prove useful in other contexts.
For an ideal way of handling cached html:
Perhaps there may be a better way of doing this, but this is what I'm thinking for now.
Perhaps the cache file shouldn't be just the raw HTML, but a plain-text formatted file:
FILE: <filename>
)VAR: 012345...
).Not sure if the HTML's size should be stored in this "header" or if it should rely on fseek/ftell to get the size. Either way, the current implementation responds to an http request with a header containing the size of the HTML being sent.
EDIT: Actually, one can count the bytes read after reaching the end of "header" when loading the HTML into memory.
Actually the non-FILE variables don't need to be individually checked. If a variable has changed, then the config has changed, and thus only the timestamp on the config file can account for them.
A format has to be decided for the cache file. Perhaps something like:
A format needs to be decided for cache filenames.
Maybe a path of
/
corresponds to "ROOT", a path of/outer
corresponds to "outer" , and a path of/outer/inner
corresponds to "outer0x2Finner". (0x2F is the/
character.)Hopefully a delimeter of
0x2F
won't actually be used in an actual path. If it is used, then perhaps support an alternate string to use as delimeter as well?URLs have
%2F
as the escaped form of/
, so perhaps that can be used as an alternative delimeter.As of
206cad6f57
, the alternate delimeter%2F
in place of0x2F
will be used if0x2F
exists in the given path. This can be checked for when turning the filename into a path by checking if it starts with%
due to how the first slash is converted into either delimeter.Thinking about it, I'm not sure if a http client will pass escaped characters directly in the request. It probably would be best to convert such escaped characters during processing. This might be worthy of being a separate issue in this issue tracker, but for now it probably would be best to add functions to convert from/to escaped form and to use a delimeter other than
%2F
.