From POSIX to COM/DCOM or RMI to SOAP, we simply try to share data among threads or applications. By decoupling service with client, Memcached is a new and better solution to share data. Because Memcached is an abstract service, it can serve different applications written in different programming languages running on different platforms simultaneously.
Memcached is 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. In short, Memcached is a huge hashmap.
Now, let's study the results of the tests above. When user A login, there was no dummy data in memcached. So, the dummy service generated dummy data and stored it in memcached under key "dummy#A". When user A refresh the page, dummy service was able to grep data right out of memcached, so no new dummy data was generated. Since we set timer as 10 seconds for dummy data to stale, new dummy data need to be generated after a timeout. From these, we can see how memcached caches data. But does it work the same way as hard coding? When user B login, there was no dummy data for that user in memcached yet. All memcached had was for user A, so dummy service generated a new dummy data for user B under key "dummy#B". From there, user B should have the same experience as user A had.
MemCached is just that simple.
In web applications the majority of the latency in serving a request is caused by interactions with a database. Databases are often necessary for managing persistence and to providing a way to sort and filter large collections of information. However, databases are also overused to frequently read and write infrequently-changed information -- or worse, information that never changes.Memcached provides a shared memory cache where arbitrary information can be read frequently without incurring the overhead of a database.
Refer : http://wiki.cerb4.com/wiki/Performance#Memcached
Memcached is 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. In short, Memcached is a huge hashmap.
public class DummyServiceImpl {
//CustomMemCachedClient is wrapper class internally developed in our product to access cache
private CustomMemCachedClient mCustomMemCachedClient;
public String retrieveDummy(String regId) {
String dummy = null;
String key = "dummy#" + regId;
Object cachedValue = mCustomMemCachedClient.get(key);
if (cachedValue instanceof String) {
dummy = (String)cachedValue;
}
if (dummy == null) {
dummy = "dummy has been set for regId: " + regId;
System.out.println("dummy is just set for " + regId);
mCustomMemCachedClient.set(key, dummy);
}
return dummy;
}
public CustomMemCachedClient getCustomMemCachedClient() {
return mCustomMemCachedClient;
}
public void setCustomMemCachedClient(
CustomMemCachedClient pCustomMemCachedClient) {
mCustomMemCachedClient = pCustomMemCachedClient;
}
}
Now, let's study the results of the tests above. When user A login, there was no dummy data in memcached. So, the dummy service generated dummy data and stored it in memcached under key "dummy#A". When user A refresh the page, dummy service was able to grep data right out of memcached, so no new dummy data was generated. Since we set timer as 10 seconds for dummy data to stale, new dummy data need to be generated after a timeout. From these, we can see how memcached caches data. But does it work the same way as hard coding? When user B login, there was no dummy data for that user in memcached yet. All memcached had was for user A, so dummy service generated a new dummy data for user B under key "dummy#B". From there, user B should have the same experience as user A had.
MemCached is just that simple.
In web applications the majority of the latency in serving a request is caused by interactions with a database. Databases are often necessary for managing persistence and to providing a way to sort and filter large collections of information. However, databases are also overused to frequently read and write infrequently-changed information -- or worse, information that never changes.Memcached provides a shared memory cache where arbitrary information can be read frequently without incurring the overhead of a database.
Refer : http://wiki.cerb4.com/wiki/Performance#Memcached
No comments:
Post a Comment