Science Fair Projects Ideas - Memcached

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Memcached


memcached is a distributed memory caching system that was originally developed by Danga Interactive for LiveJournal. It is used to speed up dynamic database-driven websites by caching data and objects in memory to reduce the amount the database needs to be read. memcached is open source and released under a BSD license. It uses libevent .

Memcached lacks authentication and security features, meaning it should only be used on servers with a firewall set up appropriately.

MediaWiki is one example of software that supports memcached. Slashdot uses memcached in some parts of its site.

memcached acts as a giant hash table, caching data as it is requested. Originally designed to speed up only the queries themselves, memcached is now often used in object caching as well. Any task which is time intensive can be improved by using memcached to store the data, rather than regenerate it every time, so long as the cached data has either a definite expiry time or a process through which the cached data can be marked as deletable.

Converting your database or object creation queries to use memcached is simple. Typically, if you are using straight database queries, you might have code that looks like the following:

function foo (int userid) {
   result = db_select("SELECT * FROM users WHERE userid = " + foo);
   return result;
}

After conversion to memcached, the same call might look like the following:

function get_foo (int userid) {
    result = memcached_fetch("userrow:" + userid);
    if (result) {
        return result;
    }
    result = db_select("SELECT * FROM users WHERE userid = " + foo);
    memcached_add("userrow:" + userid,  result);
    return result;
}

As you can see, you would first check whether a memcached value with the unique key "userrow:userid" exists, where userid is some number. If the memcached_fetch call returns the data, you immediately return - and never need to touch the database or slow disks. If the result does not exist, you would select from the database as usual, and set the unique key using the memcached API add function call.

However, if you only modified this API call, and no others, you would eventually end up fetching incorrect data (assuming your entire database doesn't fit into the memory caching you have available). In addition to creating a "add" call, you would also need to implement an update call, using the memcached set function.

function update_foo(int userid, string dbUpdateString) {
    result = db_execute(dbUpdateString);
    if (result) {
        data = createUserDataFromDBString(dbUpdateString);
        memcached_set("userrow:"+userid, data);
    }
}

This call would update the currently cached data to match the new data in the database, assuming the database query succeeds.

Note that all functions described on this page are pseudocode only. Memcached calls and programming languages may vary based on the API you use.

External links

03-10-2013 05:06:04
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice