A high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load
Features
Very Fast
APIs
Hash Table
LRU
High Performance
Slab Allocator
Disadvantages
Lacks Access Control
Security
1.Installation #Download the extension module apt-get install php5-memcache # Edit /etc/php5/conf.d/memcache.ini and uncomment the following line by removing the semi-colon extension=memcache.so # Restart apache etc/init.d/apache2 restart
Implementation
PHP:
<?
$memcache = new Memcache;
$memcache->connect ( 'localhost', 11211 ) or die ( "Could not connect" ) ;
?>
Example:
$sql = "select * from pages where page_id=1";
$qry = mysql_query ( $sql ) or die ( mysql_error () ." : $sql" ) ;
$result = mysql_fetch_object ( $qry ) ;
$content = $result->content;
$sql = "select * from pages where page_id=1";
$key = md5 ( 'query'.$sql ) ;
$result = $memcache->get ( $key ) ;
if ( $result == null) {
$qry = mysql_query ( $sql ) or die ( mysql_error () ." : $sql" ) ;
0 comments
Post a comment