Memcache

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Memcache - Presentation Transcript

    1. Memcache
    2. 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
    3. Features
      • Very Fast
      • APIs
      • Hash Table
      • LRU
      • High Performance
      • Slab Allocator
    4. Disadvantages
      • Lacks Access Control
      • Security
    5. 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
    6. Implementation
      • PHP:
      • <?
      • $memcache = new Memcache;
      • $memcache->connect ( 'localhost', 11211 ) or die ( &quot;Could not connect&quot; ) ;
      • ?>
      • Example:
      • $sql = &quot;select * from pages where page_id=1&quot;;
      • $qry = mysql_query ( $sql ) or die ( mysql_error () .&quot; : $sql&quot; ) ;
      • $result = mysql_fetch_object ( $qry ) ; 
      • $content = $result->content;
      • $sql = &quot;select * from pages where page_id=1&quot;; 
      • $key = md5 ( 'query'.$sql ) ; 
      • $result = $memcache->get ( $key ) ; 
      • if ( $result == null) {  
      • $qry = mysql_query ( $sql ) or die ( mysql_error () .&quot; : $sql&quot; ) ; 
      • if ( mysql_num_rows ( $qry ) > 0 ) {
      • $result = mysql_fetch_object ( $qry ) ;
      • $memcache->set ( $key,$result,0,3600 ) ; 
      • }
      • }
    7. Functions
      • Memcache::add
      • Memcache::get
      • Memcache::connect
      • Memcache::delete
      • Memcache::addServer
      • Memcache::close
    8. Memcache::add <?php $memcache_obj = memcache_connect(&quot;localhost&quot;, 11211); $memcache_obj->add('var_key', 'test variable', false, 30); ?>
    9. Memcache::connect <?php $memcache = new Memcache; $memcache->connect('memcache_host', 11211); ?>
    10. Memcache::delete <?php $memcache_obj = new Memcache; $memcache_obj->connect('memcache_host', 11211); $memcache_obj->delete('key_to_delete', 10); ?>
    11. Memcache::get <?php $memcache_obj = new Memcache; $memcache_obj->connect('memcache_host', 11211); $var = $memcache_obj->get('some_key'); ?>
    12. References: http://in.php.net/memcache http://phpbuilder.com/manual/en/intro.memcache.php http://www.hostingcoupons.org/what-is-memcached/
    13. Thank You…
    SlideShare Zeitgeist 2009

    + MobME TechnicalMobME Technical Nominate

    custom

    293 views, 0 favs, 0 embeds more stats

    Memcache

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 293
      • 293 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 3
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories