Effective Memcache

what-is-memcached

Everyone wants to have a fast website, especially web developers, but nowadays, fast is not enough if it runs fast only at certain condition. Many people still complain a lot about their website speed, since their website still could not handle a number of their visitors even though they have been provided by expensive hosting. Today we are going to introduce you with Memcache, a solution for your website’s speed.

What is it?

Lately, being fast is one thing but working efficiently is another thing, no wonder Memcache has been so popular lately, Memcache is a distributed RAM cache where you can store transient data using a key-value model. With Memcache , you can access to Memcached item much faster compared with data in persistent storage systems. The tradeoff is that data held in Memcache is transient and is evicted as the system runs out of Memcache space. In fact, because of Memcache and its faster operation times, you can greatly improve the responsiveness of your application as a lookup layer or transient storage in addition to your primary storage.

How Should I Use It?

There are likely several places in which Memcache could be used to improve performance, depending on the design of your application. Below are several examples of Memcache usage which will encourage you to use it in your own application:

  • Caching popular pages
  • Saving transient, frequently updated, data
  • Caching frequently fetched entities

When to Use a Memory Cache

One advantages of memory cache is that it can speed up common datastore queries. If there are so many requests that produce the same query with the same parameters, and changes to the results do not need to appear on the web site immediately, the application can cache the results in the Memcache.  Subsequent request can check the Memcache, and if the results are absent or expires, it only performs the datastore query. Data that will be good to be cached are usually session data, user preferences, and other data returned by queries for web pages.

Besides, Memcache is also useful for other temporary values. However, you need to make sure that your application could adapt very well when the value is suddenly not available. Moreover, at any time your value can expire from the Memcache and can be expired since it has the expiration deadline set for the value.

Ajax, a Technique for Better Web Applications

whatisajax

Have you ever used AJAX? Many web developers and app developers who like to make their website run faster and efficient will choose AJAX as their solutions. AJAX is actually a technique that has been applied in many popular social media which aims for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS, and Java Script. It works by retrieving data only in part that you need to change instead of reload the whole page. AJAX is an acronym that stands for Asynchronous JavaScript and XML. So far, AJAX is the most workable Rich Internet Application (RIA) technology. But at the same time, AJAX has browser incompatibility and it is supported by JavaScript, which is difficult to maintain and debug.

Along with Document Object Model and JavaScript for dynamic content display, Ajax uses XHTML for content and CSS for presentation. In conventional web applications transmit information to and from the server done through synchronous requests. AJAX is usually required to fill out a form, hit submit, and get to a new page directed with new information from the server while with AJAX, JavaScript will make a request to the server, interpret the results, and update the current screen once you hit the submit. In this sense, the user will never discover that anything was even transmitted to the server which causes better user experience compare to the conventional method.

Moreover, by using AJAX, a user can continue to use the application while the client program requests information from the server in the background. Besides, AJAX is also a more intuitive and natural user interaction, for example you may not require any clicking a mouse movement is a sufficient event trigger.

AJAX also standardizes to accomplish the following standards:

  • Browser-based presentation using TML and Cascading style sheets (CSS).
  • JavaScript to make everything happen.
  • Behind-the-scenes data fetches using XMLHttpRequest objects in the browser.
  • Data is stored in XML format and fetched from the server.

PICASSO VS GLIDE (Advantage and disadvantage)

picasso-vs-glide

Currently, mobile developers keep looking for a new method to make image loading run faster. Today, we are going to see the difference between the two most popular image loader library, Picasso and Glide. Both of them may have their own advantage and disadvantage, even though they may look 90% similar. In fact, some resources said that Glide is Picasso-clone. Anyway in details, it is quite different. Especially in several ways below:

Import to Project

dependencies {
 compile ‘com.squareup.picasso:picasso:2.5.1’
}

 

Glide

dependencies {   
compile ‘com.github.bumptech.glide:glide:3.5.2’   
compile ‘com.android.support:support-v4:22.0.0’
}

 

Glide also requires Android Support Library v4, so bear in mind to import support-v4 to your project like above as well. Frankly, you basically need Android Support Library v4 in every single new-age Android project, so it should not be kind of problem for you.

Image’s Quality in Details

The image’s quality between the two may not be too different, but Picasso is better known that is has better image quality. As you can see on the images below, Glide has some hard pixels and is not as smooth as the Picasso one and it is difficult to find the straight way to change image resizing algorithm.

picasso

Disk Caching

In terms of default disk caching concept, Picasso and Glide are quite different. In the experiment below, the same Full HD image is loaded into ImageView with Picasso and Glide. When I checked the cache folder, it appears that Glide cached the ImageView-size (768×432 pixels) while Picasso cached the full size one (1920×1080 pixels).

picasso

If you see closer on the picture above, you will see the hard pixels described above is also there. In addition, if image is loaded in RGB565 mode, the cached image will be also in RGB565.

Moreover, other difference occurs when you try to adjust ImageView to the different sizes. Picasso will cache only single size of image, the full-size one while Glide acts differently, it caches separate file for each size of ImageView. You also need to download an image that has already been loaded if you need to load another size the same image before be resized to the right resolution and then be cached.

Anyway you could use this command to adjust its behavior by let Glide cache both the full-size image and the resized one.

Glide.with(this)            
.load(“http://nuuneoi.com/uploads/source/playstore/cover.jpg”)             .diskCacheStrategy(DiskCacheStrategy.ALL)            
.into(ivImgGlide);

 

The full-size image would be loaded from cache, resized and then cached, the next time image is requested to show on any ImageView. Due to this, Glide can load and show image faster than Picasso, while Picasso may take longer time to load images since it needs to be resized first before it is set to an ImageView.

GIF

Compared to Picasso,  Glide also has an ability to load GIP animation to a simple ImageView which makes it more interesting. However, if you would like to use GIF, you should use it wisely, since it consumes quite a lot of memory. Glide is also able to decode any local video file to a still image.

Furthermore, you can configure the way image appears with an animator (R.animator) while Picasso could do only one animation, fading in.