SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best way to store semi static variables?

    Hi. this must be quite a common problem...

    Say i have a list of categories (or something like that) which i want to display on all pages of a site which a user will visit.

    Now my list is stored in my database and although it will/can change, it is very unlikely to change very often. So ideally, i dont want to have to fetch the data from a database everytime the user loads a page. so what is the best way of going about this?

    i have come up with the following possible solutions:

    1.) Caching.
    This is probibly the best way to go about doing it...but unfortunately i dont know much about server side caching and have been too lazy to really get into it (maybe i should).

    If anyone would like to give an explanation of caching and an example, that would be nice . Please also note that i dont want to go the PEAR cache route..

    2.) Manually (or automatically) updating an included html file when categories are added. -> build this into the CMS / site administration.

    3.) Storing the variables in a $_SESSION, so you only read in the list of categories once per users' session. Although obviosly this method will be a bit dodgy for people who dont have sessions enabled in their browsers.

    in ASP one can use the application variable for this type of storage...

    Im sure im not the first to come across this problem. what is the standard way of doing it? does anyone have any ideas which i might not have mentioned?

    Cheers.

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Option 2 is probably your best bet. I do something like that with the RSS feeds on my site. Those change maybe once a week, so I created semi-dynamic pages to keep my RSS feeds updated. Just write your content to a file rather than a web page, and your problem is solved.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no one else got any other suggestions...?

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Leuven, Belgium
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A fourth option, that a lot of CMS's would use, is to put these in your database. I like your option #2 much better though, if you don't have a separate caching option.

    An 'drop-in' caching solution: see http://www.jpcache.com/ - download and follow the 'quick usage' instructions on the front page of their site.

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless you have thousands of categories, you're probably best off just to leave them in the database and pull them as required. Particularly if you'll be opening a connection to the database anyway.

    Unless you want to avoid making a connection to the database at all, and want to cache whole pages without having to reconstruct them every time...in which case I do recommend looking into Smarty or PEAR:Cache, although it's not too hard to roll your own thing.

  6. #6
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    caching is a generic term which covers many scenarios , 1 of those indeed is item 2 on your list.

    like viny-junkie I keep static copies of arrays of such data which are included at runtime , when the data in the DB changes then the script that handles the DB update also rebuilds the included file so there is no need to to anything manually apart from writing the original script.

    In some cases the DB update script will also build complete javascript menus etc save building them at runtime.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •