Saturday, 26 January 2013

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached is a general-purpose distributed memory caching system that was originally developed by Danga Interactive for LiveJournal, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached runs on Unix, Linux, Windows and Mac OS X and is distributed under a permissive free software license.

Memcached's APIs provide a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.


Architecture

 

 

 




 

 

Who uses Memcache?


  • YouTube
  • Reddit
  • Zynga
  • Facebook
  • Orange
  • Twitter
  • Wikipedia
  • Heroku offers a managed memcached service built on Couchbase Server as part of their platform as a service.
  • Google App Engine, AppScale, Windows Azure and Amazon Web Services also offer a memcached service through an API

Used For?

 

 

 


Pros

1) Reduces database load.
2) Perfect for websites with high database load.
3) Significantly reduces the number of retrieval requests to database
4) Cuts down the I/O access (hard disk)

Cons

1) Not a persistent data store.
2) Not a database.
3) Not application specific
4) Cannot cache large object

Configuring Memcached (For Ubuntu)


Step 1) Install Libevent
Memcached uses the Libevent library for network IO.
$ cd libevent-1.4.11-stable$ autoconf
$
./configure --prefix=/usr/local
$
make
$
sudo make install
Step 2) Install Memcached
Download the latest version of Memcached from Danga.com who developed
Memcached originally for Livejournal.
$ cd memcached-1.4.0$ autoconf$ ./configure --prefix=/usr/local$ make$ sudo make install
Step 3) Run memcached
Start memcached as a daemon with 512MB of memory on port 11211(default).
Then you can telnet to the server and port and use any of the available commands.
$ memcached -d -m 512 127.0.0.1 -p 11211
$
telnet localhost 11211Trying ::1...
Connected to localhost.
Escape character is '^]'.
get joe
END
set joe 0 3600 10  (Note: TTL 3600 and 10 bytes)California
STORED
get joe
VALUE joe 0 10
California
END
Step 4) Spy Memcached (Memcached Java Client)

public class Users implements Serializable{
       private int id;
private String name ;
    // Getter and Setter methods
}

public class MemcachedDemo {
public static void main(String[] args) {
Users users = new Users();
users.setId(1);
users.setName("Sunil123");
try {
MemcachedClient c=new MemcachedClient(new InetSocketAddress("127.0.0.1", 1121));
               c.set("someKey_1", 2592000, users);
               Object myObject=c.get("someKey_1");
               System.out.println("Object 1: " + myObject);
               System.out.println("Statistics: " + c.getStats());
               System.out.println("Statistics of individual Items: " + c.getStats("items"));
               c.delete("someKey_2");
               c.shutdown();
               c=null ;
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
}

26 comments:

  1. Thanks for sharing this webpage.It is really good and useful.
    Regards,
    AWS Training | AWS Training in Chennai | AWS course in Chennai

    ReplyDelete
  2. Awesome blog with informative content... thanks for sharing such a wonderful blog... Java Training in Chennai | Dot Net Training in Chennai

    ReplyDelete
  3. Amazing blog about the various informative information of the programming languages. PHP is one such programming language which is more easier to learn and has lot of scope in future which is provided in Php Training institute in Chennai

    ReplyDelete
  4. I have read your blog its very Interesting. Thanks for sharing. ERP Providers in Chennai | ERP in Chennai. We provide best quality cost effective ERP software applications and end to end enterprise solutions to all the industry verticals with the affordable cost.

    ReplyDelete
  5. Thank you for this valuable information. I have got some important suggestions from it. I'm working in Brave Technologies Private Limited. We provides lowest price of ERP Software for our clients. Contact us on info@bravetechnologies.in
    Manufacturing ERP software Chennai | Automotive ERP in Chennai

    ReplyDelete
  6. Really an amazing post..! By reading your blog post i gained more information.

    Bulk SMS Services in Chennai

    ReplyDelete
  7. Very Nice Post…Thanks.Very interesting and Helpful Tips…..Thanks For Sharing.

    Executive MBA Distance Education

    ReplyDelete

  8. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete

  9. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Android App Development Company

    ReplyDelete

  10. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.i am expecting more updated posts from your hands.
    iOS App Development Company
    iOS App Development Company

    ReplyDelete
  11. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete
  12. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text

    ReplyDelete
  13. it is really amazing...thanks for sharing....provide more useful information...
    Mobile app development company

    ReplyDelete

  14. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well

    iOS App Development Company
    Android App Development Company

    ReplyDelete
  15. Excellent concept with understandable manner. Thanks for sharing such a nice blog. Software Testing Training Institute in Chennai | Selenium Training Institute in Chennai

    ReplyDelete
  16. Thanks for taking the time to discuss this Database topic and I feel very happy about it. Keep Sharing.. Best Dot Net Training in Chennai | Best Java Training in Chennai | Best Web Design Training in Chennai

    ReplyDelete
  17. Excellent information from your article..I really love reading and following your post as I find them extremely informative and interesting.
    Best B.E/B.Tech Project Center in Chennai | No.1 M.E/M.Tech Projects in Chennai | Best IT Project Center in Chennai


    ReplyDelete

Find me on Facebook! Follow me on Twitter!