How to set up smartphones and PCs. Informational portal
  • home
  • news
  • External storage caching [. What is cache memory? What is cache for "Android"

External storage caching [. What is cache memory? What is cache for "Android"

Caching Is one of the ways to optimize Web applications. In any application, there are slow operations (SQL queries or queries to external APIs), the results of which can be saved for some time. This will allow fewer of these operations to be performed, and the majority of users will be able to display the previously saved data.

The most popular caching technology for Web applications is Memcache.

When to cache

Try to avoid caching unless absolutely necessary. This is a simple technique, but it reduces the flexibility of the application. Don't do unnecessary work ahead of time, but include the possibility of using caching in the future:

  • Use classes or functions to work with data. Do not use duplicate SQL selections in the main application.
  • Use wrappers to work with external APIs.

What to cache?

You need to cache data that is slowly generated and often requested. In practice, this is usually:

  • Results of requests to external services (RSS, SOAP, REST, etc.).
  • Results of slow samples from the database.
  • Generated html blocks or entire pages.

Caching database selections

Database queries are the most common example. It is very simple to implement on the basis of Memcache:

! $ list = memcache_get ("online_users")) ($ sql = "SELECT * FROM users WHERE last_visit> UNIX_TIMESTAMP () - 60 * 10"; $ q = mysql_query ($ sql); while ($ row = mysql_fetch_assoc ($ q)) $ list = $ row; memcache_set ("online_users", $ list, 60 * 60);) return $ list; ) $ list = get_online_users (); ...

# Request to get users is cached for 1 hour

Updating data

If you cache data that can be updated, you need to clear the cache after each update:

memcache_delete ("user". $ id); }

List caching

Let's say you cache the data of each user, as in the example, as well as their lists (for example, a list of online users). When you refresh user data, you delete data from the cache for the specified user only. But his data can also be present in the list of online users, which are also in the cache. It is not efficient to flush the lists every time any user's data is refreshed. Therefore, this approach is usually used:

  1. Caches lists that only consist of user IDs.
  2. To display the list, a separate request is sent to get the data of each user.

The implementation looks like this:

id FROM users WHERE last_visit> UNIX_TIMESTAMP () - 60 * 10 "; $ q = mysql_query ($ sql); while ($ row = mysql_fetch_assoc ($ q)) $ list = $ row ["id"]; memcache_set ("online_users", $ list, 60 * 60); ) return $ list; ) $ list = get_online_users (); foreach ($ list as $ id) ($ user = get_user ($ id); ...)

# Get a list of user IDs and get actual data for each of them

To get data from several objects at once, you can use Multiget.

Repeated requests

Some data may be requested several times within one page, for example:

get_user ($ _ SESSION ["id"]) ["name"])?>

... Email:get_user ($ _ SESSION ["id"]) ["email"]?> ... get_user ($ _ SESSION ["id"]) ["nick"]?> "> My Page ...

Every call get_user () will get data from the cache. If Memcache is on a separate server, it will cause a lot of network traffic and latency.

To avoid this, you can use an additional cache inside the application itself:

global $ app_cache; if ($ app_cache ["user". $ id]) return $ app_cache ["user". $ id]; if (! $ data = memcache_get ("user". $ id)) ($ sql = "SELECT * FROM users WHERE id =". intval ($ id); $ q = mysql_query ($ sql); $ data = mysql_fetch_assoc ( $ q); memcache_set ("user". $ id, $ data, 60 * 60); $ app_cache ["user". $ id] = $ data;) return $ data; ) function save_user ($ id, $ data) ( global $ app_cache; mysql_query ("UPDATE users SET ... WHERE id =". intval ($ id)); memcache_delete ("user". $ id); unset ($ app_cache ["user". $ id]); }

In real applications, it makes sense to have a Memcache wrapper with an additional cache:

inner_cache)) return $ this-> inner_cache [$ key]; $ data = memcache_get ($ this-> resource, $ key); $ this-> inner_cache [$ key] = $ data; return $ data ["value"]; ) public static function set ($ key, $ value, $ ttl) (memcache_set ($ key, $ value, $ ttl); $ this-> inner_cache [$ key] = $ value;) public static function del ($ key) (memcache_delete ($ key); unset ($ this-> inner_cache [$ key]);))

# $ inner_cache stores additional cache

Attention. Using this approach can lead to memory leaks when working with a large amount of data in the cache. For example, in cron tasks (let's say we iterate over all users to send a mailing list). Then it's better to add disabling the internal cache:

public static $ inner_cache_enabled = true; public static function get ($ key) (if ( self :: $ inner_cache_enabled&& array_key_exists ($ key, $ this-> inner_cache)) return $ this-> inner_cache [$ key]; $ data = memcache_get ($ this-> resource, $ key); $ this-> inner_cache [$ key] = $ data; return $ data ["value"]; ) public static function set ($ key, $ value, $ ttl) (memcache_set ($ key, $ value, $ ttl); if (self :: $ inner_cache_enabled)$ this-> inner_cache [$ key] = $ value; ) public static function del ($ key) (memcache_delete ($ key); unset ($ this-> inner_cache [$ key]);)) ... mem_cache :: $ inner_cache_enabled = false;

# Disable internal cache

Warming up

When updating particularly heavy data, you should not use a flush of the cache, but a direct update of the data in it:

# operations to update external resources $ data = file_get_contents ("http://rss.com/rss"); memcache_set ("rss", $ data, 60 * 60); }

This will avoid the extra burden of doing heavy selections when the key is removed. This technique is commonly used in cron jobs to periodically update the results of very heavy selections.

Lifetime (TTL)

ttl (time to live) is the time after which the data will be removed from the cache. The Memcache is installed in seconds:

60*60 );

# Installing ttl for 1 hour

Most often, ttl is played from a few minutes to several days. Do not use the value 0 (infinite storage), it can clog up memory.

LRU

Any cache works on the principle of preemption if it runs out of memory. Those. if Memcache can use a maximum of 1G of memory, and you are trying to store keys at 2G, then Memcache will delete half of this data. To determine which keys to delete, the LRU (Least Recently Used) algorithm is used:

Memcache will try to delete, first of all, the data that was requested a very long time ago (i.e., it will delete less popular data and leave more popular ones).

Caching very slow queries

Imagine you have a query that takes 10 seconds to complete. You save it to your cache for 1 hour. When this time passes, the data in the cache is deleted. In the first 10 seconds after that, you are faced with a situation where several users simultaneously call this difficult request. This can lead to disastrous consequences. within 10 seconds there can be several hundred or thousands of such calls.

To avoid this, you must use a special duplication technique.

Atomic operations

Sometimes the cache stores counters (for example, the number of users). When adding new users, instead of resetting the counter and resampling, you can simply increase the cache value by one. But you cannot do this through the application, because this will result in data loss from two concurrently executed queries:

Memcache supports two atomic operations for increasing and decreasing numbers:

# Increase counter by 1, function memcache_decrement () decrements counter

The most important

Caching in Memcache-based applications is a very powerful tool. Do not forget that Memcache does not guarantee the safety of your data. This means that you cannot rely on the fact that the data saved for 60 minutes will be in the cache for exactly 60 minutes.

Although ExpressionEngine builds your web pages very quickly, you will notice that there is a direct correlation between page load speed and the amount of dynamic information it contains. The more tags and variables you use, the more processing cycles the templating engine must complete.

The caching technology in ExpressionEngine consists of several independent data caching systems and settings.

Query caching

The query caching system remembers the results of queries from your database, storing each query as a text file. When visitors access your web pages, the cache files are checked for specific requests that are required when creating the pages. If found, ExpressionEngine uses the data from the cache instead of querying your database. This provides a significant reduction in the overall load on your database. The query caching system is completely dynamic, which means that it automatically updates itself when new information is added to your database.

Some queries cannot be cached because their syntax changes dynamically on each execution. A basic section display query, for example, always checks that the post's posting end date matches the current time to determine if the post's posting date is over. This forces the system to make changes to queries on every page load; therefore it is not possible to use standard query caching for it. (See for an alternative that can be used in many cases.)

The request caching system provides anywhere from 30% to 90% - a reduction in the total number of requests depending on how your pages are created.

This feature can be manually disabled on the database configuration page in the control panel.

Tag caching

The tag caching system allows you to cache the output of individual tags. This gives you the ability to render some parts of your pages completely dynamically, while leaving others for static rendering. By caching individual tags, you reduce the number of scripts and server resources required to render any page, while maintaining fully dynamic presentation only where it is needed.

The tag cache is kept for a user-defined time interval. After the specified time interval, the cache is automatically refreshed.

To enable tag caching, add the following two parameters for any tag:

Cache = "yes" refresh = "10"

Note: refresh indicates the time, in minutes, between cache updates.

For example, to cache a tag for 30 minutes, you would do the following:

(exp: weblog: entries cache = "yes" refresh = "30")

Template caching

Template caching (or dynamic page caching) allows you to cache all templates, making your pages a lot lighter. Since ExpressionEngine requires multiple scripts and database queries to manage core resources, you cannot get 100% static pages, there will always be a little less.

Template caching, like tag caching, is time-based. To enable template caching, click the "Settings" link on the templates page. On it, you must enable caching, and set the update time interval.

We call this dynamic page caching because the system clears the cache automatically when certain events occur. For example, if you cache a comment page, when someone adds a comment, the cache will be cleared, momentarily canceling the caching setting.

Note: Template caching replaces tag caching. There is no additional benefit to using tag and template caching at the same time. If page caching is enabled, no other types of caching are in effect. Therefore, if you want to cache individual tags, turn off page caching.

Caching dynamic section queries

This setting is located on the Admin> Global Section Settings page. This function will increase the processing speed of the (exp: weblog: entries) tag by caching requests that are usually done dynamically. This option, however, is not suitable for all people.

Enable this feature only if you not use "future" or "past" records.

Disabling requests

The disable = parameter is available in the (exp: weblog: entries) tag. It allows you to disable tag features that you are not using to improve performance. The weblog entries tag is designed to fetch a lot of information by default: Categories, Custom Fields, User Data, etc. Depending on how you use the tag, some of this information may not be needed. With the "disable" parameter, you can disable these features of the tag to make it more "lightweight".

The syntax for the disable parameter is: disable = "ITEM YOU WANT TO DISABLE". There are five elements that can be turned off:

  • categories
  • category_fields
  • custom_fields
  • member_data
  • pagination
  • trackbacks

You can disable multiple items by separating them as shown below:

Disable = "categories | member_data | trackbacks"

The best approach is to examine the data you output using the tag on a case-by-case basis. If there is a data type that you are not using, disable it.

For example, if you use the weblog entries tag to display the titles of the 10 most recent entries:

(exp: weblog: entries orderby = "date" sort = "desc" limit = "10")
(title)

(/ exp: weblog: entries)

In this example, you only display the titles of your posts, nothing else; however, the weblog tag retrieves categories and other data automatically. Using the disable = parameter, you can disable unnecessary functions in order to exclude them from the request. In our case, you do not need any of the functions, and all of them can be disabled.

(exp: weblog: entries orderby = "date" sort = "desc" limit = "10" disable = "categories | custom_fields | member_data | pagination | trackbacks")
(title)

(/ exp: weblog: entries)

Note: You can also use parameter disable = "category_fields" in tags

What is cache? Is it possible to clear the cache of applications on an android phone? Yes you can. Do I need to clear the cache on android? It is necessary and unnecessary.

Why it is necessary and unnecessary, and what to do for you, determine by reading this entry to the end, although the principle is simple: by clearing the cache, you will get more memory, but the speed of data access may decrease.

The number of applications in the majority of owners is constantly increasing. Sometimes so large that it slows down the system.

Therefore, you should get rid of them periodically. In newer versions, you can do this with a single button.

Go to "Settings", then to the memory tab, then to the data cache. You will be asked if you want to get rid of all data.

This step can be set to automatically repeat periodically to help keep the system in good shape.

How the cache works

Is the application cache in an android phone relatively small compared to the storage capacity of a smartphone or tablet?

Its task is to reduce the access time for data processing and to minimize the load on the RAM in order to make it available to other devices.

It bridges the gap between productivity gains and media access speeds.

The use of cache memory has two advantages: reduced access time and more efficient use through the built-in intelligent storage algorithm.

The memory controller detects a sequence of frequently repeated operations and intercepts them during execution and replaces them with data from the cache.

Thus, the processor retains a long way to access main memory. The loop in the cache is many times faster than if it were taken from main memory.

What happens if you delete the cache

Nothing will happen if you delete the memory cache. It is a collection of data that is a "blueprint" of the original values ​​stored elsewhere.

In other words, the cache is a temporary storage where frequently used data can be stored for quick access to it.


Android device caching is a memory subsystem based technology. The main goal is to speed up your android to complete tasks much faster.

To understand the basic concept of caching, take a look at a simple librarian example.

When the first client arrives for a book, the librarian goes to the warehouse and returns to the counter with the book to give to the client.

Later, the client returns to return the book. The librarian takes the book to the warehouse, returns to the counter and waits for another client.

Let's assume that the next client needs this very book. The librarian must go back to the warehouse to take the book again and take it to the new client.


According to this model, the librarian must make a complete path to bring each book. Let's attach a cache to the librarian - give him a backpack in which he can store 10 books.

In this backpack, he will put the books that clients return - a maximum of 10. Now, when another client arrives, all that is required from the librarian is to take a book from the backpack and give it to the client, so the client is served faster.

Almost everything works this way on an android phone. As you can see, a lot also depends on the volume and cleaning - the speed of service decreases, in our case it is the performance of the android system.

Therefore, the conclusion is this: you can clear the cache on android, but whether you need to clear it is up to you. Good luck.

The computer, alas, does not immediately execute the commands it receives from people. A number of tricks are used to speed up this process, and caching takes pride of place among them. What it is? What is cached data? How does this process actually take place? What is cached data in a Samsung smartphone, for example, and is it different from what is in a computer? Let's get down to getting answers to these questions.

This is the name of the intermediate buffer, which provides quick access to information, the probability of which is most likely to be requested. All data is contained in it. An important advantage is that you can retrieve all the information you need from the cache much faster than from the original store. But there is a significant drawback - the size. Cached data is used by browsers, hard drives, CPUs, web servers, WINS, and DNS. The structure is based on recordsets. Each of them is associated with a certain element or block of data, which act as a copy of what is in the main memory. Records have an identifier (tag), which is used to determine the match. Let's look from a slightly different perspective: what is cached data in a Samsung phone or another manufacturer? Are they different from those created in the computer? From a fundamental point of view - no, the difference is solely in size.

Use process

When a client (they were listed above) requests data, the first thing the computer does is examine the cache. If it contains the required entry, then it is used. In these cases, a hit occurs. Periodically, data from the cache is copied to the main memory. But if the required entry was not found, then the content is searched in the underlying storage. All the information taken is transferred to the cache so that later it can be accessed more quickly. The percentage that requests are successful is called the hit rate or hit rate.

Updating data

When used, let's say a web browser checks the local cache to find a copy of the page. Given the limitations of this, in case of a miss, a decision is made to discard some of the information in order to free up space. Various preemptive algorithms are used to decide what will be replaced. By the way, if we talk about what cached data on Android is, then for the most part they are used to work with pictures and application data.

Recording policy

During the modification of the contents of the cache, the data in the main memory is also updated. The time lag that elapses between the entry of information depends on the entry policy. There are two main types:

  1. Immediate recording. Each change is synchronously recorded in the main memory.
  2. Deferred or writeback. Data is updated periodically or upon request from the client. To track whether a change has been made, a flag with two states is used: "dirty" or changed. In the event of a miss, two calls can be made, directed to the main memory: the first is used to write data that has been changed from the cache, and the second is used to read the required item.

It may be that the information in the intermediate buffer becomes irrelevant. This happens when data in main memory changes without making adjustments to the cache. For consistency of all editing processes, coherence protocols are used.

Contemporary challenges

With an increase in the frequency of processors and an increase in the performance of RAM, a new problem area has appeared - the limited interface. What of this can a knowledgeable person notice? Cache memory is very useful if the frequency in the RAM is less than in the processor. Many of them have their own intermediate buffer to reduce the access time to RAM, which is slower than registers. CPUs that support virtual addressing often have a small but very fast buffer of address translation. But in other cases, the cache is not very useful, and sometimes it only creates problems (but this is usually in computers that have been modified by a non-professional). By the way, speaking about what is cached data in the memory of a smartphone, it should be noted that due to the small size of the device, new miniature cache implementations have to be created. Some phones now boast the parameters of advanced computers ten years ago - and what a difference in their size!

Synchronizing data between different buffers

  1. Inclusive. The cache can behave as you please.
  2. Exclusive. Developed for each specific case.
  3. Non-exclusive. Widespread standard.

Caching levels

Their number is usually three or four. The higher the memory level, the larger and slower it is:

  1. L1 cache. The fastest cache level is first. In fact, it is part of the processor, since it is located on one die and belongs to functional blocks. It is usually divided into two types: instruction and data caches. Most modern processors do not work without this level. This cache operates at the processor frequency, so it can be accessed every clock cycle.
  2. L2 cache. Usually located together with the previous one. It is a shared memory. To find out its value, it is necessary to divide the entire volume allocated for data caching by the number of cores in the processor.
  3. L3 cache. Slowest but largest dependent cache. Usually more than 24 MB. Used to synchronize data that comes from different L2 caches.
  4. L4 cache. The use is justified only for high-performance multiprocessor mainframes and servers. It is implemented as a separate microcircuit. If you ask a question about what is data caching in a Samsung smartphone and are looking for this level in it, I can say that they were in a hurry for 5 years.

Cache associativity

This is a fundamental characteristic. The associativity of the cached data is required to display logical segmentation. It, in turn, is needed due to the fact that sequential enumeration of all available lines takes dozens of clock cycles and negates all the advantages. Therefore, a hard binding of RAM cells to the cache data is used to reduce the search time. If we compare intermediate buffers that have the same volume, but different associativity, then the one with a large associativity will work less quickly, but with significant specific efficiency.

Conclusion

As you can see, cached data, under certain conditions, allows your computer to act faster. But, alas, there are still quite a few aspects that can be worked on for a long time.

Probably, many users of computers and mobile devices, at least occasionally, have come across such a concept as "cached data". What it is, many, frankly, simply do not imagine. However, using advice on speeding up any device with an operating system, they know for sure that the cache needs to be cleared. This is partly true, but not all data can be deleted. It happens that without them, some programs installed on the device simply will not work.

What does "cached data" mean in general terms?

So, let's look at the general concept. Roughly speaking, this term describes the data stored in a computer or mobile system to speed up subsequent access to some applications or sites on the Internet by downloading information, the call of which in the usual way takes more time.

To make it clearer, you can give an example of how cached data is used. What is it, for example, if a user visits a web page on which he looks at photographs? These are copies of them in the form of thumbnails, which are saved in a special folder on the hard disk of a computer or on the internal storage of a mobile device. When re-entering the page, the user does not have to wait until all the content is loaded (for example, graphics, video and, in general, multimedia), since all elements are added to the page just from the cache directory.

in phone?

But this was only a general justification. Everything is clear with the Internet. Now let's see what the cached application data on the phone is (meaning applets other than web browsers).

Actually, this information is somewhat similar in essence to the saved data from the Internet, only for the most part it is associated with saving settings or specific content of any program with which the operating system works. To make it a little clearer, let's look at a few examples below.

Examples of using the cache

Let's take a look at some of the basic data types that you can or cannot delete. In the first case, this applies to any applications installed on the system, unless the use of an additional cache, which is different from the system one, is provided for their full functionality.

But with the special content of the cache, which quite often needs to be copied to a phone or tablet on its own or additionally downloaded from the Internet, the situation is somewhat different.

The simplest example is game cached data. What could it be? Anything you want: additional textures, graphics, video, audio, or even the parameters of the game itself. Such information, as it is already clear, cannot be deleted in any case, since then the game simply will not start or it will give an error stating that this and that is not enough to start.

The same goes for some music apps for mobile devices. Take FL Studio Mobile as an example. Even the app's own installer doesn't have everything a sequencer needs to run. In other words, only the main shell is installed.

What is the cached application data on the phone in relation to this type of application? These are sets of tools, effects, settings for interaction with other applets, options for supporting certain audio formats, etc. As a rule, such a cache is saved in a special obb folder, which is located on the internal drive, unless it is indicated that it can be placed on a removable card memory. Such information takes up a lot of places, but without it the application will be non-functional (what is only one software shell, in which there are no tools or effects?).

Clearing the cache on a mobile device using standard tools

What is cached data in the phone, we figured it out a bit. Now let's look at the issues of cleaning such content, since it tends to slow down the system.

Any Android device has two cache cleaning tools. The first is designed to delete data for all applications, the second allows you to clear the cache for only one single applet.

If you want to delete the whole, the settings menu is used, in which the memory section is selected. When tapping on a line of cached data, the system issues a warning that all information will be deleted. We just agree and wait for the cleaning to complete.

Now a few more words about what cached application data is in terms of deleting it for a separately selected applet. You can find information on them in the same memory section, but with the transition to the applications menu.

Next, you just need to select the desired applet, and after entering its menu from the bottom, tap on the button to clear the cache. In general, both the first and second methods look somewhat inconvenient, since in this case the so-called deletion from different sources can be performed. Therefore, it is better to use special programs.

Using optimizers and cleaners

Today, many such programs have been created by analogy with stationary computer systems. In the same repositories in the Play Market or AppStore, you can find not even dozens of them, but hundreds.

Cached data (which is already clear) can be deleted for the entire system, and for each selected applet.

As far as the programs themselves are concerned, narrowly focused applications and applets for general optimization seem to be the most preferred. The former are represented by programs such as App Cache Cleaner, Auto Cahe Cleaner, etc.

Among the optimizers, we can especially highlight the mobile versions of CCleaner, All-in-one Toolbox, and many others. What exactly to use is already a matter of personal preference, because each such program has its own pros and cons.

Instead of a total

That's all about understanding the term "cached data". What it is, I think, is already clear to most users. However, the issue of cleaning such information must be approached with extreme caution, since for some types of programs, as mentioned above, it may be necessary in the work. But as practice shows, it is better to turn to general-purpose utilities. In them, the cache clearing tool is a required module. And when using them, you can also speed up the system at the same time.

Top related articles