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

[eluser]OwanH[/eluser]
[quote author="BlkAngel" date="1184043776"]Hehe. The PHP manual is nothing new to me, but I was curious if there was a solution to the caching issue, since I don't want to recurse a directory with every page access. That is the real question I have.[/quote]

Yup, there is. I would definitely go with the idea of caching the directory heirarchy using a DB. I've written a class for you that does just that but before delving into the code though let me explain the DB tables that are needed. Here's the SQL I used to create them:

Code:
CREATE TABLE directory_tree (
    entry_id int(10) unsigned NOT NULL auto_increment,
    entry_name varchar(255) NOT NULL default '',
    entry_type enum('File','Folder') NOT NULL default 'File',
    parent_id int(10) unsigned NOT NULL default '0',
    PRIMARY KEY  (entry_id)
) ENGINE=MyISAM;

CREATE TABLE ptr_directory_tree_root (
    root_entry_id int(10) unsigned NOT NULL default '0',
    PRIMARY KEY  (root_entry_id)
) ENGINE=MyISAM;

Now the directory_tree table is used to store your filename and heirarchy information whereas the ptr_directory_tree_root table stores a single value and that is the ID of the row in the directory_tree table that stores the info. for the root directory.

Here's a breakdown of the fields in the directory_tree table:

entry_id - Unique ID of a single entry in the directory tree.
entry_name - The entry name (file/folder name)
entry_type - Is it a file or a folder?
parent_id - The parent folder entry id

Looks like I have too many characters in the code to fit in this post, so I'll post the code for the controller class that does the ground work immediately after this post.


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



Theme © iAndrew 2016 - Forum software by © MyBB