views:

150

answers:

2

I'm creating a cms and have not yet settled on the matter of where to store the complete url for a given page in the structure.

Every page have a slug (url friendly name of the page) and every page has a nullable (for top-level pages) parent and children.

Where do I store the complete url (/first-page/sub-page) for a given page? Should this go in the database along with the other properties of the page or in some cache?

Update

It's not the database design I'm asking about, rather where to store the complete url to a given page so I don't need to traverse the entire url to get the page that the user requested (/first-page/sub-page)

Update 2

I need to find which page belongs to the currently requested url. If the requested url is /first-page/sub-page I don't want to split the url and looping through the database (obviously).

I'd rather have the entire url in the table so that I can just do a single query (WHERE url = '/first-page/sub-page') but this does not seem ideal, what if I change the slug for the parent page? Then I also need to update the url-field for all descendants.

How do other people solve this issue? Are they putting it in the database? In a cache that maps /first-page-/sub-page to the id for the page? Or are they splitting the requested url and looping though the database?

Thanks

Anders

A: 

Store it in a cache, because the web servers will need to be looking up URLs constantly. Unless you expect the URLs of pages to change very rapidly, caching will greatly reduce load on the database, which is usually your bottleneck in database driven web sites.

Basically, you want a dictionary that maps URL -> whatever you need to render the page. Many web servers will automatically use the operating system's file system as the dictionary and will often have a built-in cache that can recognize when a file changes in the file system. This would probably be much more efficient than anything you can write in your CMS. It might be better, therefore, to have you CMS implement the structure directly in the file system and handle additional mapping with hard or soft links.

Joseph Bui
Should I store the id of the page in the cache or the entire page object?
loraderon
Are the pages just HTML? Are they interpreted scripts? What web server software are you using? Do your machines have enough RAM to cache everything?
Joseph Bui
Do you have to perform any database queries to generate the final HTML?
Joseph Bui
I'm probably going to cache the output on the disk. So it will make sense to just store the id in the cache I think.Thank you guys
loraderon
A: 

I just did this for MvcCms. I went with the idea of content categories/sub categories and content pages. When a content category / subcategory is created I go recursively through the parents and build the entire route and then store it in the category table. Then when the page is requested I can find the correct content page and find out when going through a nav structure if the current nav being built is the current or active route.

This approach requires some rules about what happens when a category is edited. The approach right now is that once the full path is set for a sub category it can't be change later with the normal tools.

The source is a mvccms.codeplex.com

MvcCmsJon