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();
           }
       }
}

49 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. 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
  5. Really an amazing post..! By reading your blog post i gained more information.

    Bulk SMS Services in Chennai

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

    Executive MBA Distance Education

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

    ReplyDelete
  8. 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
  9. 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
  10. Thanks For Your valuable posting, it was very informative
    Webdesign Lüdenscheid


    ReplyDelete
  11. Thank you very much for your very informative post. In my opinion, I can offer you to read an article with a similar topic on how mobile applications can boost sales of your business in 2017 :https://softwaredevelopment.ae/can-mobile-app-development-increase-2017-sales/

    ReplyDelete
  12. this is really too useful and have more ideas from yours. keep sharing many techniques.
    Java Project Center in Chennai | Best Java Projects in Velachery

    ReplyDelete
  13. I really enjoyed while reading your article, the information you have delivered in this post was damn good. Keep sharing your post with efficient news.
    MSC Project Center in Chennai | MSC Project Center in Velachery

    ReplyDelete
  14. Informative blog and it was up to the point describing the information very effectively. Thanks to blog author for wonderful and informative post.
    Mobile application developers in Chennai | Android application developers in Chennai | Android app
    developers Chennai
    | PHP developers chennai

    ReplyDelete
  15. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    android training in bangalore

    ReplyDelete
  16. I am so happy to read such a wonderful post...Thank you for updating...VLSI Project Center in Chennai | VLSI Project Center in Velachery

    ReplyDelete
  17. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog...
    MCA Project Center in Chennai | MCA Project Center in Velachery

    ReplyDelete
  18. Thanks for this grateful information. all this information is very important to all the users and can be used good at all this process.
    Web Designing Training Institute in Chennai | Web Designing Training Institute in Velachery

    ReplyDelete
  19. Thanks a lot for Sharing the valuable information keep posting everyone ..Java Project Center in Chennai | Java Project Center in Velachery

    ReplyDelete
  20. I read that Post and got it fine and informative. Please share more like that..
    hr and payroll software in chennai

    ReplyDelete
  21. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us

    java training in omr

    java training in annanagar | java training in chennai

    java training in marathahalli | java training in btm layout

    java training in rajaji nagar | java training in jayanagar


    ReplyDelete
  22. I love the information you provide here and can’t wait to take a look when I get home. I’m surprised at how fast your blog loaded on my cell phone. I’m not even using WIFI, just 3G. Anyways, awesome blog!
    fire and safety course in chennai

    ReplyDelete

  23. Thank you sharing the info very well explained.
    MCSE Training in Delhi

    ReplyDelete
  24. Finish the Selenium Training in Chennai from Infycle Technologies, the best software training institute in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Java, Hadoop, Big Data, Android, and iOS Development, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.

    ReplyDelete
  25. Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today! https://just99marketing.com/wordpress-web-design

    ReplyDelete

Find me on Facebook! Follow me on Twitter!