Caching design about the part of data

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
coolesting
Forum Newbie
Posts: 13
Joined: Thu Sep 02, 2010 12:36 am

Caching design about the part of data

Post by coolesting »

About this cache, normally, there are two way to choose in php,

the first, just like the memcache with the memory,
the second, it be a file in hard disk.

Ok, now , i cannot use this first scheme base on the server, but i have some data of the category of the article to be stored with an array by caching , as the following to show.

Code: Select all

$cache_category = array(
    1 => array('name' => 'php', description => 'something here'),
    2 => array('name' => 'mysql', description => 'something here'),
    3 => array('name' => 'css', description => 'something here'),
    4 => array('name' => 'html', description => 'something here'),
    5 => array('name' => 'js', description => 'something here'),
    //perhaps it remain about ten more rows currently
);
i saved as a php file in the hard disk, if want to use it just include that file is ok.
however, something that confusing to me,what if the number of cache files in the hard disk be increased day by day, what if the record of data in a cache file be more and more,
the circumstance that the disk space is not sufficient,

but the database is still more free space , i created a table and call name is cache_table, let it store the cache data instead of file caching in the hard disk, i think it is the third way to solve this problem , whereas it generate another problem that need some time when the php connect the database, this is why i counld be confused.

if you encounter this situation, how to do , thanks to good idea or improvement suggestion.
User avatar
coolesting
Forum Newbie
Posts: 13
Joined: Thu Sep 02, 2010 12:36 am

Re: Caching design about the part of data

Post by coolesting »

Nobody interest ? my god, help me, just a idea .
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Caching design about the part of data

Post by josh »

Garbage collection is a concept in computer science of deleting temporary records after a certain amount of time has passed. If you use a caching framework like Zend Framework it handles this, and allows switching between memcache and hard drive on the fly, by changing one single setting.
User avatar
coolesting
Forum Newbie
Posts: 13
Joined: Thu Sep 02, 2010 12:36 am

Re: Caching design about the part of data

Post by coolesting »

Hi, josh,

i know what you said, but i just care about the efficiency of the application.
so i give up the framework, and make a little code or a function to replace that framework.

now, i consider that the caching is by hard disk or by database , whereas the connection of the database is need some time that confused me , as we know, the connection is very slow in certian time.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Caching design about the part of data

Post by josh »

That's a poor reason to spend all that time writing your own. Existing cache solutions are plenty fast, running some of the world's top websites. You're not going to innovate caching by writing a new PHP function. Existing solutions already support memcache which are 100s of times faster than your hard drive based solution will be. Honestly the only valid reason to write your own caching function (with all the open source solutions) is to learn.

It doesn't really matter how good or fast your cache is, if the rest of your application moves slowly anyways, or doesn't do something useful - then you didn't really accomplish anything at the end of the day.

Like I said, write it to learn - by all means, but that's all its going to end up being probably. A learning experience.
Post Reply