Welcome Guest, Not a member yet? Register   Sign In
Automatic templating of text files within a directory (with caching)
#8

[eluser]OwanH[/eluser]
[quote author="BlkAngel" date="1184114143"]Thank you! I'll have some fun playing around with this.

Two questions that come to mind immediately are:
1) What is the caching strategy? How do you know when to retrieve a new copy and re-populate the DB?

2) For my specific application, would it be wiser to attempt to convert your controller into an externally loaded library instead? The controller aspect of it would, in line with my app idea, be reserved for templating and parsing directories, it seems.[/quote]

Well the truth is I wanted to see if I could implement a solution to your problem that wasn't too overly complicated just to see if I was on the right track about exactly what you were asking. It definitely could be and needs to be more extensive but hopefully I was on the right track Smile.

So, to answer your questions:

1) The caching strategy is pretty simple: check if the directory tree structure has been cached each time a request comes in for the root directory or any sub-directories n-levels deep (where n >= 1 and is really only limited by storage space and server resource limits). If it is then we get a listing of the directory's contents from the DB cache, otherwise the cache is created on the fly, that is the DB is populated. Now as the code stands, there are a couple of caveats, as explained below:

1.1) There are no checks in place to determine if any file/folder within the heirarchy has been modified since it's info. was cached, and so the DB is never re-populated after the first cache is created. This of course could be easily implemented by adding a last_modified timestamp field to the directory_tree table to store the time the file/directory was last modified. That way, if a cache exists when a request is made then a system call can be made to check the time of the most recent modification against the value stored in the last_modified field and if the system call's reported time is more recent the cache would be deleted and re-created for that file/directory, and of course recursive checks could be made on sub-directories. Also full pathnames should be stored in the DB for each directory/file with info. cached (the class currently only stores full pathnames for files, not directories).

1.2) The code currently lacks strong error-checking, for things like cache references to deleted/non-existent files or folders. Like I said earlier, I didn't wanna make the code look too complicated.

2) Yes I agree 100% that it would be better and wiser to convert this controller into an externally loaded library that has the core routines for managing the directory cache or "index". The library could take care of creating/updating/deleting the cache, and provide interface methods for retrieving/updating directory listings and file content, etc. That way, like u said, your controller could be reserved for templating and parsing directories, and hey you could even throw in a couple views to display your heirarchy links if you feel dangerously MVC Smile.


Messages In This Thread
Automatic templating of text files within a directory (with caching) - by El Forum - 07-10-2007, 04:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB