CN116450966A - Cache access method and device, equipment and storage medium - Google Patents

Cache access method and device, equipment and storage medium Download PDF

Info

Publication number
CN116450966A
CN116450966A CN202310404824.4A CN202310404824A CN116450966A CN 116450966 A CN116450966 A CN 116450966A CN 202310404824 A CN202310404824 A CN 202310404824A CN 116450966 A CN116450966 A CN 116450966A
Authority
CN
China
Prior art keywords
cache
annotation
configuration
target
configuration attribute
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310404824.4A
Other languages
Chinese (zh)
Inventor
陈小平
程铄生
尹泉
黄文强
邱晓辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Foshan Viomi Electrical Technology Co Ltd
Original Assignee
Foshan Viomi Electrical Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Foshan Viomi Electrical Technology Co Ltd filed Critical Foshan Viomi Electrical Technology Co Ltd
Priority to CN202310404824.4A priority Critical patent/CN116450966A/en
Publication of CN116450966A publication Critical patent/CN116450966A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the application discloses a cache access method and device, equipment and storage medium; the method comprises the following steps: receiving a cache configuration instruction, wherein the cache configuration instruction is used for configuring a cache of the electronic equipment; in response to a cache configuration instruction, obtaining a cache annotation set corresponding to a cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotations, automatic refreshing cache annotations, random expiration time annotations, automatic refreshing filter annotations and NULL value cache expiration time annotations; analyzing the cache annotation set to obtain configuration attributes of each cache annotation in the cache annotation set; and executing the cache operation corresponding to the configuration attribute on the cache according to each configuration attribute. Thus, by setting different cache annotations, various cache problems occurring during caching can be prevented.

Description

Cache access method and device, equipment and storage medium
Technical Field
Embodiments of the present application relate to computer technology, and relate to, but are not limited to, a cache access method, a device, an apparatus, and a storage medium.
Background
The cache is a technology frequently used by a website server, and in a business scene with more read and less write, the cache can be used for effectively supporting high concurrent access quantity, so that data sources such as a back-end database and the like are well protected. The high-speed small-capacity memory is arranged between a CPU (Central Processing Unit, a central processing unit) and a memory, can buffer data stored in part of the memory, and directly provides the data for the CPU when the CPU needs to access the data so as to solve the problem of unmatched transmission speed between the CPU and the memory. When a website uses a cache, it is usually checked whether data exists in the cache, if so, the content of the cache is directly returned, if not, the database is directly queried, and then the query result is cached.
At present, a plurality of cache products, such as Redis, memcached, are available in the market, no matter which cache product is used, the problems of cache breakdown, cache avalanche, cache penetration and the like are basically encountered, and the existing cache access mode is complex and has poor fault tolerance. Therefore, how to effectively prevent various problems occurring when buffering occurs is a difficult problem that must be solved.
Disclosure of Invention
In view of this, the cache access method, device, equipment and storage medium provided in the embodiments of the present application can solve the problems of cache breakdown, cache avalanche, cache penetration, etc. occurring during caching by setting different cache annotations. The cache access method, the device, the equipment and the storage medium provided by the embodiment of the application are realized as follows:
in a first aspect, a cache access method provided in an embodiment of the present application includes:
receiving a cache configuration instruction, wherein the cache configuration instruction is used for configuring a cache of the electronic equipment;
in response to a cache configuration instruction, obtaining a cache annotation set corresponding to a cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotations, automatic refreshing cache annotations, random expiration time annotations, automatic refreshing filter annotations and NULL value cache expiration time annotations;
Analyzing the cache annotation set to obtain configuration attributes of each cache annotation in the cache annotation set;
and executing the cache operation corresponding to the configuration attribute on the cache according to each configuration attribute.
In the technical scheme, the cache of the electronic equipment is configured by receiving a cache configuration instruction, and a cache annotation set corresponding to the cache is obtained in response to the cache configuration instruction, wherein the cache annotation set comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation; and then, according to the configuration attribute of the one or more cache notes, executing the cache operation corresponding to the configuration attribute on the cache, so that the problems of cache breakdown, cache avalanche, cache penetration and the like in the process of caching can be solved through the multiple functions of the cache notes.
In some embodiments, obtaining a set of cache annotations corresponding to a cache includes:
and scanning the target path corresponding to the cache to obtain a scanning result of the target path, wherein the scanning result comprises a cache annotation set.
In the technical scheme, the scanning path corresponding to the cache can be preset, and after the cache configuration instruction is received, the cache annotation set is automatically acquired according to the preset scanning path, so that the cache configuration efficiency is improved.
In some embodiments, the caches include a local cache and a remote cache, each cache annotation including a cache type field for indicating a target cache to which the cache annotation is to be applied, the target cache including the local cache and/or the remote cache.
In the technical scheme, multi-level caching can be realized, and the cache configuration of different caches is realized through the cache type field, so that the operation is convenient.
In some embodiments, according to each configuration attribute, performing a cache operation on the cache corresponding to the configuration attribute, including:
determining a target cache corresponding to each cache annotation according to the cache type field of each cache annotation;
and executing the cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation.
In the above technical solution, by implementing the analysis of the cache type field, the attribute configuration for each cache may be automatically implemented, so that the electronic device may automatically execute the corresponding cache operation according to the configuration attribute.
In some embodiments, the cache annotation is a concurrent loading protection annotation, the configuration attribute of the concurrent loading protection annotation is a cache key value, and according to the configuration attribute of each cache annotation, executing a cache operation corresponding to the configuration attribute on the target cache, including:
And executing data loading operation on the cache content in the target cache based on the single thread according to the cache key value of the concurrent loading protection annotation.
In some embodiments, the cache annotation is an auto-refresh cache annotation, the configuration attribute of the auto-refresh annotation is a refresh condition, and according to the configuration attribute of each cache annotation, executing a cache operation corresponding to the configuration attribute on the target cache, including:
and at the target cache, refreshing the content meeting the refreshing condition in the target cache.
In some embodiments, the cache annotation is a random expiration time annotation, the configuration attribute of the random expiration time annotation is a random expiration condition, and according to the configuration attribute of each cache annotation, performing a cache operation corresponding to the configuration attribute on the target cache, including:
and at the target cache, clearing the content with the storage time meeting the random expiration condition in the target cache.
In some embodiments, the cache annotation is a NULL value cache expiration time annotation, a configuration attribute of the NULL value cache expiration time annotation is a NULL value expiration condition, and according to the configuration attribute of each cache annotation, executing a cache operation corresponding to the configuration attribute on the target cache, including:
And at the target cache, clearing the null content with the storage time meeting the null expiration condition in the target cache.
In the technical scheme, the concurrent loading control, the refreshing processing control and the clearing control of the national enterprise content and the NULL value content of the cache content are realized through the concurrent loading protection annotation, the automatic refreshing cache annotation, the random expiration time annotation and the NULL value cache expiration time annotation, so that the occurrence probability of cache breakdown, cache avalanche and cache penetration can be reduced.
In some embodiments, the method further comprises:
and starting a cache configuration function of the electronic equipment and setting a target path.
In the technical scheme, the switch can be arranged on the cache configuration function, so that the execution of the function can be flexibly controlled, and the function can be controlled to be closed when the cache configuration is not needed, so that the read-write resource consumption of the electronic equipment is reduced. Moreover, the target path for scanning can be set in advance, so that the efficiency of cache configuration is improved.
In a second aspect, a cache access device provided in an embodiment of the present application includes:
the receiving module is used for receiving a cache configuration instruction, wherein the cache configuration instruction is used for configuring the cache of the electronic equipment;
The response module is used for responding to the cache configuration instruction, acquiring a cache annotation set corresponding to the cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation;
the analysis module is used for analyzing the cache annotation set to obtain the configuration attribute of each cache annotation in the cache annotation set;
and the execution module is used for executing the cache operation corresponding to the configuration attribute on the cache according to each configuration attribute.
In a third aspect, the present application provides an electronic device comprising a processor and a memory for storing code instructions; the processor is configured to execute the code instructions to implement the method in the first aspect.
Optionally, the processor is one or more and the memory is one or more.
Alternatively, the memory may be integrated with the processor or the memory may be separate from the processor.
In a specific implementation process, the memory may be a non-transient (non-transitory) memory, for example, a Read Only Memory (ROM), which may be integrated on the same chip as the processor, or may be separately disposed on different chips.
In a fourth aspect, the present application provides a computer readable storage medium storing a computer program (which may also be referred to as code, or instructions) which, when run on a computer, causes the computer to perform the method of the first aspect described above.
In a fifth aspect, the present application provides a computer program product comprising: a computer program (which may also be referred to as code, or instructions) which, when executed, causes a computer to perform the method of the first aspect described above.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and, together with the description, serve to explain the technical aspects of the application.
FIG. 1 is a schematic diagram of one example of a caching technique in the related art;
fig. 2 is a schematic implementation flow chart of a cache access method provided in an embodiment of the present application;
fig. 3 is a schematic implementation flow chart of a cache access method provided in an embodiment of the present application;
fig. 4 is a schematic structural diagram of a cache access device according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
The technical solutions in the present application will be described below with reference to the accompanying drawings.
In order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second", etc. are used to distinguish the same item or similar items having substantially the same function and effect. For example, the first instruction and the second instruction are for distinguishing different user instructions, and the sequence of the instructions is not limited. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
In this application, the terms "exemplary" or "such as" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "for example" should not be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete fashion.
Furthermore, "at least one" means one or more, and "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: a alone, a and B together, and B alone, wherein a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b, and c may represent: a, b, or c, or a and b, or a and c, or b and c, or a, b and c, wherein a, b and c can be single or multiple.
In most internet application scenarios, caching is typically used for data with high concurrency requests. Referring to fig. 1, which is a schematic diagram of an example of a caching technology, as shown in fig. 1, a cache is located between a database and a terminal device, and after the terminal device sends an access request, a server first queries access data from the cache, so that the access request can be directly sent to the database without directly sending the access request, and the purpose of protecting a backend database is achieved by reading the cache data in the cache. However, during the design and use of the cache, some problems are often encountered, for example, the data in the cache is time-efficient, and when a large-scale cache data failure occurs at a certain moment, a large amount of cache requests are directly sent to the database to obtain corresponding information from the database, so that the pressure of the database is huge, and if the data is high in concurrency, the database is possibly instantaneously down to cause cache avalanche; for another example, the cache access is queried according to a key value (key), and if no corresponding value exists, the database search should be performed. If the value corresponding to the key is not necessarily existed and the concurrent request quantity for the key is large, a large pressure is caused on the database, so that cache penetration is caused; for another example, a hot spot has a large number of concurrent requests to access the data centrally, and the key is suddenly invalidated, so that a large number of concurrent requests are all hit on the database, and thus the pressure of the database is greatly increased, and cache breakdown is caused.
Due to the problems of cache breakdown, cache avalanche, cache penetration and the like, the protection effect on the back-end database is reduced in some cases, and the normal operation of on-line service is affected.
In view of this, the embodiments of the present application provide a cache access method, which is applied to an electronic device, where the electronic device may be various types of devices with information processing capabilities in an implementation process, and the electronic device may be a terminal device or may also be a server.
It should be appreciated that the terminal device may be a mobile phone, a tablet, a notebook, a palm, a mobile internet device (mobile internet device, MID), a wearable device, a Virtual Reality (VR) device, an augmented reality (augmented reality, AR) device, a smart screen, an artificial intelligence (artificial intelligence, AI) sound, headphones, a terminal in industrial control (industrial control), a terminal in unmanned (self driving), a terminal in teleoperation (remote medical surgery), a terminal in smart grid (smart grid), a terminal in transportation security (transportation safety), a terminal in smart city (smart city), a terminal in smart home (smart home), a personal digital assistant (personal digital assistant, PDA), etc., to which embodiments of the present application are not limited.
The server may be implemented by a stand-alone server or a server cluster formed by a plurality of servers, which is not limited in this application.
Fig. 2 is a schematic implementation flow chart of a cache access method provided in the embodiment of the present application, where multiple cache problems occurring during caching can be prevented by setting different cache annotations. As shown in fig. 2, the method may include the following steps 201 to 204:
step 201, a cache configuration instruction is received, where the cache configuration instruction is used to configure a cache of the electronic device.
Here, the cache will be described first. For common business, if a data is to be queried, the data is generally directly searched from a database; however, in the case of high traffic, directly searching the database reduces the search performance because the database search process is to take data from disk, refresh it to memory, and return the data. While disks read slower than memories, memory-based caching has emerged to improve performance.
Here, the configuration of the cache of the electronic device may be configuring a corresponding configuration file, a cache configuration parameter, etc. for the electronic device. In some embodiments, receiving the cache configuration instruction may be receiving the cache configuration instruction sent by the configuration management end, where the configuration management end may be a device that is pre-established for use by a developer, such as a manager or a development engineer, and the developer may input configuration content to the configuration management end after opening the configuration management end, where the configuration content may include a configuration file, a cache configuration parameter, and so on.
In some embodiments, the cache configuration parameters may include a cache database type configuration item, a cache time configuration item, and the like.
Step 202, in response to a cache configuration instruction, obtaining a cache annotation set corresponding to a cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotations, auto-refresh cache annotations, random expiration time annotations, auto-refresh filtering annotations and NULL value cache expiration time annotations.
An Annotation (section) is understood to be a special tag in code that can be read at compile, class load, run-time and perform the corresponding processing. Annotations are somewhat different from annotations, which can be understood as special tags in code that can be read at compile, class load, runtime, and perform the corresponding processing.
It should be noted that different buffer annotations correspond to different functions, and in the embodiment of the present application, by setting different buffer annotations in a buffer, the problems of buffer breakdown, buffer avalanche, buffer penetration and the like occurring during buffering can be effectively solved.
In some embodiments, the obtaining a set of cache annotations corresponding to the cache may be reading the set of cache annotations from a preset storage location, or may be implemented by executing step 303 in the following embodiment, which is not limited herein.
And 203, analyzing the cache annotation set to obtain the configuration attribute of each cache annotation in the cache annotation set.
In the embodiment of the application, the cache annotation comprises a plurality of attributes, the parameters of the cache annotation attributes are set, and if the parameters of the attributes are not set, the self-defined default attribute parameters are used. By setting different parameters for the attribute of the cache annotation, the cache annotation can meet the cache requirements of different scenes.
In this embodiment of the present application, the specific type of the configuration attribute of each cache annotation obtained by parsing is not limited, for example, the configuration attribute may be a name of the cache annotation, a cache key value (key), a condition of use (condition), whether to throw an exception, whether to synchronize an exception, and the like. The above configuration attribute is explained below.
Caching key values: in the cache of the memory-based database, the memory-based database is generally stored in a key-value pair (key and value) mode, and the key can be quickly positioned and the corresponding unique value can be found through hash operation.
Cache type: by setting this parameter, different types of cache selection can be made.
Whether to throw out an anomaly: when the internal error of the cache component is reported, if the setting of the throwing exception is carried out, the running exception is thrown; if the setting does not throw the abnormality, after internal error reporting, the abnormality capturing is carried out, the running abnormality is not thrown, and an empty object is returned.
Whether or not to synchronize operation: the database data is queried in different modes, synchronous is to wait for the query result and then return, asynchronous is to not need to wait for and directly return the result.
Step 204, according to each configuration attribute, executing the cache operation corresponding to the configuration attribute on the cache.
After obtaining the configuration attribute corresponding to each cache annotation, corresponding cache operation can be executed on the cache of the electronic equipment according to the function of the cache annotation and/or the corresponding execution condition of the cache annotation.
In the embodiment of the application, corresponding caching operations can be executed on the cache according to configuration attributes corresponding to one or more cache annotations in concurrent loading protection annotations, automatic refreshing cache annotations, random expiration time annotations, automatic refreshing filtering annotations and NULL value cache expiration time annotations, so as to solve the problems of cache breakdown, cache avalanche, cache penetration and the like in the process of caching.
Wherein, according to configuration attributes corresponding to one or more cache notes of concurrent loading protection notes, auto-refresh cache notes, random expiration time notes, auto-refresh filter notes, NULL value cache expiration time notes, corresponding cache operations are executed on the cache, which may be implemented by executing step 206 in the following embodiments.
In the embodiment of the application, a cache of the electronic equipment is configured by receiving a cache configuration instruction, and a cache annotation set corresponding to the cache is obtained in response to the cache configuration instruction, wherein the cache annotation set comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation; and then, according to the configuration attribute of the one or more cache notes, executing the cache operation corresponding to the configuration attribute on the cache, so that the problems of cache breakdown, cache avalanche, cache penetration and the like in the process of caching can be solved through the multiple functions of the cache notes.
The embodiment of the present application further provides a cache access method, and fig. 3 is a schematic implementation flow chart of the cache access method provided in the embodiment of the present application, as shown in fig. 3, where the method may include the following steps 301 to 306:
step 301, starting a cache configuration function of the electronic device and setting a target path.
In some embodiments, the method may be started by adding @ EnableMethodCAche to the startup class, and the target path may be specified. If a cache needs to be created by @ CreateCAche, add @ EnableCreateCAcheAnaction annotation to open. After the annotations are added in the configuration class, the spring can determine the function of needing to use the cache, other annotations related to the cache are effective, the spring is mainly realized through aop, and the method of needing to use the cache is intercepted through aop, so that the function of the cache is realized.
Step 302, a cache configuration instruction is received, where the cache configuration instruction is used to configure a cache of the electronic device.
Step 303, in response to the cache configuration instruction, scanning the target path corresponding to the cache to obtain a scanning result of the target path, where the scanning result includes the cache annotation set.
Here, the cache configuration instruction may be a scan instruction, and the scan instruction may be @ springboot application annotation, which defaults to scanning components in the package where the main program is located and all sub-packages. Further, when scanning is performed for the specified target path, the parameter scanBasePackages can be added, i.e. the function of specifying the target scanning path can be realized.
The obtained cache annotation set includes one or more of concurrent loading protection annotation @ cache interconnection protection, auto-refresh cache annotation @ cache refresh, random expiration time annotation @ cache shield, auto-refresh filter annotation @ CacheShield, NULL value cache expiration time annotation @ cache shield.
And 304, analyzing the cache annotation set to obtain the configuration attribute of each cache annotation in the cache annotation set.
In this embodiment of the present application, the specific type of the configuration attribute of each cache annotation obtained by parsing is not limited, for example, the configuration attribute may be a name of the cache annotation, a cache key value, a use condition, a cache type field, etc.
If the cache annotation is @ Cached, the cache is set, that is, the method return value is Cached, and the spring annotation obtained by analyzing the method return value is @ Cached.
The cache annotation is @ CacheUpdate, which represents updating the cache, i.e. if a key exists, the cache data is covered, if the key does not exist, the data is added to the cache, and the spring annotation obtained by analyzing the data is @ CachePut.
The cache annotation is @ CacheInvalidate, which represents an invalid cache, and the cache can be deleted according to the key, and the spring annotation obtained by analyzing the cache annotation is @ CacheEvict.
The cache annotation is @ cacheinvalidatatainer, which represents the support of one method to invalidate multiple caches.
In step 305, a target cache corresponding to each cache annotation is determined according to the cache type field of each cache annotation.
From the above analysis, the cache type field may be used to perform different types of cache selection. In this embodiment of the present application, the cache selection includes at least a local cache and a remote cache. That is, multi-level caching may also be implemented with cache annotations in embodiments of the present application.
By local cache, it is meant that data is stored locally, e.g. a static variable can be said to be a local cache. The local cache has high efficiency, directly reads the memory and has no network delay, so the local cache is more suitable under the conditions of larger performance requirements or cache contents which do not need persistence and consistency. The local cache may default to caffeine.
For large items, there will be remote caches, such as redis cache database, memcached cache database, hippo cache database. The cache and the application server are separated, the server needs to acquire data from the cache through a network request, and the application server can also generally adopt a cluster mode, so that the high availability can be ensured, the data is not easy to lose, and the consistency of the cache data of each server can be ensured. The Redis (RemoteDictionaryServer) remote dictionary service is an open-source log-type and Key Value database written and supported by ANSIC language and capable of being based on memory and being persistent.
In addition, the cache types supported by different cache annotations are different, wherein each cache annotation comprises a cache type field, and the cache type field is used for indicating a target cache acted by the cache annotation, and the target cache comprises a local cache and/or a remote cache.
For example, for concurrent loading protection notes, the corresponding target cache is a local cache; for the automatic refreshing cache annotation, the corresponding target caches are a local cache and a remote cache; for random expiration time annotation, its corresponding target cache is a remote cache; for NULL value cache expiration time notes, its corresponding target cache is a remote cache.
And 306, executing the cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation.
After the configuration attribute of each cache annotation is obtained, based on the configuration attribute of the cache annotation, executing the cache operation corresponding to the configuration attribute on the target cache corresponding to the cache annotation.
Based on the fact that the target caches corresponding to different cache annotations are different and the configuration attributes of the different cache annotations are different, the cache operations executed on the caches by the different cache annotations are different.
In the embodiment of the present application, the case that the cache performs the corresponding cache operation for different cache annotations is described:
(1) The cache annotation is the concurrent load protection annotation @ cachepennetionprotect:
and if the configuration attribute of the concurrent loading protection annotation is a cache key value, executing a cache operation on the target cache according to the concurrent loading protection annotation, and if the configuration attribute of the concurrent loading protection annotation is the cache key value of the concurrent loading protection annotation, executing a data loading operation on the cache content in the target cache based on a single thread.
Here, with concurrent load protection comments, for the same key in the same virtual machine jvm, only one thread is used to load the cache contents in the target cache, and the other threads wait for the loading result of the loading thread.
Of course, in some embodiments, a timeout is set at the same time, and if the waiting time of other threads exceeds the timeout, the thread can load itself.
The specific implementation is as follows:
@Cached(name="user:loadUserWithPenetrationProtection:",key="#userId",cacheType=CacheType.BOTH,expire=10,localExpire=5)
@CachePenetrationProtect(timeout=5)
User loadUserWithPenetrationProtection(long userId);
here, by setting the concurrent loading protection annotation, only one thread is required to load the same key, so that the situations of cache avalanche, cache breakdown, cache penetration and the like caused by simultaneous loading of multiple threads can be effectively avoided.
(2) The cache annotation is auto-refresh cache annotation @ CacheRefresh:
and if the configuration attribute of the automatic refresh annotation is a refresh condition, executing a cache operation on the target cache according to the automatic refresh annotation, and refreshing the content meeting the refresh condition in the target cache at the target cache.
Wherein the refresh condition can be implemented by setting a refresh control function that represents a screening condition for auto-refresh, using a SpEL expression setting. After the refreshing condition function is set, only the keys meeting the condition start automatic refresh, and other keys do not start automatic refresh.
Further, in some embodiments, an auto-refresh filtering cache annotation may be further set, where a configuration attribute of the auto-refresh filtering cache annotation is a refresh filtering condition, and if a cache operation is performed on the target cache according to the auto-refresh filtering cache annotation, a refresh process may be performed on a content meeting the refresh filtering condition in the target cache at the target cache.
The specific use is as follows:
@Cached(name="user:loadUserRemotelyWithRefreshCondition:",key="#userId",cacheType=CacheType.REMOTE,expire=20)
@CacheRefresh(refresh=5,stopRefreshAfterLastAccess=15)
@CacheShield(refreshCondition="#userId%2==0")
User loadUserRemotelyWithRefreshCondition(int userId);
here, by setting the auto-refresh filtering cache annotation, auto-refresh can be performed only for specific hot spot data, so that excessive execution of the operation of regularly refreshing threads in the virtual machine is avoided, and the memory explosion of the target cache is avoided.
(3) The cache annotation is a random expiration time annotation:
the configuration attribute of the random expiration time annotation is a random expiration condition, and the cache operation is executed on the target cache according to the random expiration time annotation, so that the content with the storage time meeting the random expiration condition in the target cache can be cleared.
The random expiration condition can be realized by setting a random Delta function, and after setting the random Delta, the random expiration time is a random value in the interval of [ original expiration time, original expiration time+random Delta ].
The specific implementation is as follows:
@Cached(name="user:loadUserRemotelyWithRandomExpire:",key="#userId",cacheType=CacheType.REMOTE,expire=10)
@CacheShield(randomDelta=10)
User loadUserRemotelyWithRandomExpire(long userId);
here, by setting the random expiration time annotation, different expiration times can be set for different cache entries in the target cache, so that all caches can be prevented from being invalidated at the same time, and cache avalanche is avoided.
(4) Cache annotation NULL value cache expiration time annotation:
if the configuration attribute of the NULL value cache expiration time annotation is a NULL value expiration condition, executing a cache operation on the target cache according to the NULL value cache expiration time annotation, and clearing NULL value contents with storage time meeting the NULL value expiration condition in the target cache.
It will be appreciated that the buffer capacity is limited, it is not possible to buffer all data, and penetration occurs when uncached data is queried when a large request is faced. Therefore, in the embodiment of the present application, by adding a NULL value to the cache, when the corresponding data is not requested, a NULL value may be returned to the request, so as to avoid cache penetration.
It can be seen that the precondition for performing NULL value cache expiration time annotation is that NULL values are stored in the cache. In some embodiments, to implement storing NULL values in the cache, the NULL value cache function may be turned on first, by setting cacheNullValue.
However, since NULL values are not actually business and occupy space, if NULL values are excessively cached, data existing in the cache itself is also eliminated, resulting in a decrease in cache hit rate. To solve this problem, in the embodiment of the present application, NULL value buffer expiration time annotation is provided at the same time, so that when the NULL value in the target buffer meets the expiration condition, the NULL value is cleared.
Wherein, the null value expiration condition can be realized by setting a null value expire function.
The specific implementation is as follows:
@Cached(name="user:loadUserRemotelyWithNullExpire:",key="#userId",cacheType=CacheType.BOTH,expire=100,cacheNullValue=true)
@CacheShield(randomDelta=0,nullValueExpire=5)
User loadUserRemotelyWithNullExpire(long userId);
here, by setting NULL value cache expiration time annotation, on one hand, cache penetration is avoided by using NULL value in the cache, and on the other hand, random clearing is performed on NULL value, and the decrease of cache hit rate is avoided.
In the embodiment of the application, a cache configuration function of the electronic equipment is started, and a target path is set; receiving and responding to a cache configuration instruction for configuring a cache of the electronic equipment, scanning a target path corresponding to the cache to obtain a scanning result of the target path, wherein the scanning result comprises a cache annotation set which comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation; and then, analyzing the cache annotation set to obtain the configuration attribute of each cache annotation in the cache annotation set, and determining a target cache corresponding to each cache annotation according to the cache type field of each cache annotation, so that the cache operation corresponding to the configuration attribute is executed for the target cache according to the configuration attribute of each cache annotation. Thus, the conditions of cache avalanche, cache breakdown, cache penetration and the like are solved by setting concurrent loading protection notes, memory explosion of a target cache is avoided by setting automatic refreshing filtering cache notes, cache avalanche is avoided by setting random expiration time notes, and cache penetration is avoided by setting NULL value cache expiration time notes.
It should be understood that, although the steps in the flowcharts described above are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described above may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, and the order of execution of the sub-steps or stages is not necessarily sequential, but may be performed alternately or alternately with at least a part of the sub-steps or stages of other steps or other steps.
Based on the foregoing embodiments, the embodiments of the present application provide a cache access device, where the device includes each module included, and each unit included in each module may be implemented by a processor; of course, the method can also be realized by a specific logic circuit; in an implementation, the processor may be a Central Processing Unit (CPU), a Microprocessor (MPU), a Digital Signal Processor (DSP), a Field Programmable Gate Array (FPGA), or the like.
Fig. 4 is a schematic structural diagram of a cache access device provided in the embodiment of the present application, as shown in fig. 4, the device 400 includes a receiving module 401, a response module 402, an analyzing module 403, and an executing module 404, where:
a receiving module 401, configured to receive a cache configuration instruction, where the cache configuration instruction is used to configure a cache of the electronic device;
a response module 402, configured to obtain a cache annotation set corresponding to a cache in response to a cache configuration instruction, where the cache annotation set includes one or more of concurrent load protection annotation, auto-refresh cache annotation, random expiration time annotation, auto-refresh filter annotation, NULL value cache expiration time annotation;
the parsing module 403 is configured to parse the cache annotation set to obtain a configuration attribute of each cache annotation in the cache annotation set;
and an execution module 404, configured to execute, on the cache, a cache operation corresponding to the configuration attribute according to each configuration attribute.
In some embodiments, the response module 402 is specifically configured to scan the target path corresponding to the cache, so as to obtain a scan result of the target path, where the scan result includes the cache annotation set.
In some embodiments, the caches include a local cache and a remote cache, each cache annotation including a cache type field for indicating a target cache to which the cache annotation is to be applied, the target cache including the local cache and/or the remote cache.
In some embodiments, the execution module 404 is specifically configured to determine, according to the cache type field of each cache annotation, a target cache corresponding to each cache annotation; and executing the cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation.
In some embodiments, the cache annotation is a concurrent load protection annotation, the configuration attribute of the concurrent load protection annotation is a cache key value, and the execution module 404 is specifically configured to execute, according to the cache key value of the concurrent load protection annotation, a data load operation on the cache content in the target cache based on a single thread.
In some embodiments, the cache annotation is an auto-refresh cache annotation, the configuration attribute of the auto-refresh annotation is a refresh condition, and the execution module 404 is specifically configured to refresh, at the target cache, the content in the target cache that satisfies the refresh condition.
In some embodiments, the cache annotation is a random expiration time annotation, the configuration attribute of the random expiration time annotation is a random expiration condition, and the execution module 404 is specifically configured to perform, at the target cache, a cleaning process on the content stored in the target cache for which the time satisfies the random expiration condition.
In some embodiments, the cache annotation is a NULL value cache expiration time annotation, the configuration attribute of the NULL value cache expiration time annotation is a NULL value expiration condition, and the execution module 404 is specifically configured to perform, at the target cache, a clearing process on NULL value content stored in the target cache for a time that satisfies the NULL value expiration condition.
In some embodiments, the apparatus further includes a processing module, where the processing module is configured to turn on a cache configuration function of the electronic device and set a target path.
The description of the apparatus embodiments above is similar to that of the method embodiments above, with similar advantageous effects as the method embodiments. For technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
It should be noted that, in the embodiment of the present application, the division of the modules by the cache access device shown in fig. 3 is schematic, which is merely a logic function division, and other division manners may be adopted in actual implementation. In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units. Or in a combination of software and hardware.
It should be noted that, in the embodiment of the present application, if the method is implemented in the form of a software functional module, and sold or used as a separate product, the method may also be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or part contributing to the related art, and the computer software product may be stored in a storage medium, including several instructions for causing an electronic device to execute all or part of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read Only Memory (ROM), a magnetic disk, an optical disk, or other various media capable of storing program codes. Thus, embodiments of the present application are not limited to any specific combination of hardware and software.
The embodiment of the application provides a computer device, which may be a server, and an internal structure diagram thereof may be shown in fig. 5. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is for storing data. The network interface of the computer device is used for communicating with an external terminal application program through a network connection. The computer program, when executed by a processor, implements a cache access method.
The present embodiment provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor, implements the steps of the method provided in the above embodiment.
The present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the steps of the method provided by the method embodiments described above.
It will be appreciated by those skilled in the art that the structure shown in fig. 5 is merely a block diagram of some of the structures associated with the present application and is not limiting of the computer device to which the present application may be applied, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, the cache access apparatus provided herein may be implemented in the form of a computer program that is executable on a computer device as shown in fig. 5. The memory of the computer device may store the various program modules that make up the cache access means. The computer program constituted by the respective program modules causes the processor to execute the steps in the cache access method of the respective embodiments of the present application described in the present specification.
It should be noted here that: the description of the storage medium and apparatus embodiments above is similar to that of the method embodiments described above, with similar benefits as the method embodiments. For technical details not disclosed in the storage medium, storage medium and device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" or "some embodiments" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" or "in some embodiments" in various places throughout this specification are not necessarily referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. It should be understood that, in various embodiments of the present application, the sequence numbers of the foregoing processes do not mean the order of execution, and the order of execution of the processes should be determined by the functions and internal logic thereof, and should not constitute any limitation on the implementation process of the embodiments of the present application. The foregoing embodiment numbers of the present application are merely for describing, and do not represent advantages or disadvantages of the embodiments. The foregoing description of various embodiments is intended to highlight differences between the various embodiments, which may be the same or similar to each other by reference, and is not repeated herein for the sake of brevity.
The term "and/or" is herein merely an association relation describing associated objects, meaning that there may be three relations, e.g. object a and/or object B, may represent: there are three cases where object a alone exists, object a and object B together, and object B alone exists.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments are merely illustrative, and the division of the modules is merely a logical function division, and other divisions may be implemented in practice, such as: multiple modules or components may be combined, or may be integrated into another system, or some features may be omitted, or not performed. In addition, the various components shown or discussed may be coupled or directly coupled or communicatively coupled to each other via some interface, whether indirectly coupled or communicatively coupled to devices or modules, whether electrically, mechanically, or otherwise.
The modules described above as separate components may or may not be physically separate, and components shown as modules may or may not be physical modules; can be located in one place or distributed to a plurality of network units; some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in each embodiment of the present application may be integrated in one processing unit, or each module may be separately used as one unit, or two or more modules may be integrated in one unit; the integrated modules may be implemented in hardware or in hardware plus software functional units.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware related to program instructions, and the foregoing program may be stored in a computer readable storage medium, where the program, when executed, performs steps including the above method embodiments; and the aforementioned storage medium includes: a mobile storage device, a Read Only Memory (ROM), a magnetic disk or an optical disk, or the like, which can store program codes.
Alternatively, the integrated units described above may be stored in a computer readable storage medium if implemented in the form of software functional modules and sold or used as a stand-alone product. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or part contributing to the related art, and the computer software product may be stored in a storage medium, including several instructions for causing an electronic device to execute all or part of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a removable storage device, a ROM, a magnetic disk, or an optical disk.
The methods disclosed in the several method embodiments provided in the present application may be arbitrarily combined without collision to obtain a new method embodiment.
The features disclosed in the several product embodiments provided in the present application may be combined arbitrarily without conflict to obtain new product embodiments.
The features disclosed in the several method or apparatus embodiments provided in the present application may be arbitrarily combined without conflict to obtain new method embodiments or apparatus embodiments.
The foregoing is merely an embodiment of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes and substitutions are intended to be covered in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (11)

1. A cache access method, characterized in that it is applied to an electronic device, the method comprising:
receiving a cache configuration instruction, wherein the cache configuration instruction is used for configuring a cache of the electronic equipment;
responding to the cache configuration instruction, and acquiring a cache annotation set corresponding to the cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation;
analyzing the cache annotation set to obtain configuration attributes of each cache annotation in the cache annotation set;
and executing the cache operation corresponding to the configuration attribute on the cache according to each configuration attribute.
2. The method of claim 1, wherein the obtaining a set of cache annotations corresponding to the cache comprises:
and scanning the target path corresponding to the cache to obtain a scanning result of the target path, wherein the scanning result comprises the cache annotation set.
3. The method according to claim 1 or 2, wherein the caches comprise a local cache and a remote cache, each cache annotation comprising a cache type field, the cache type field being used to indicate a target cache on which the cache annotation acts, the target cache comprising the local cache and/or the remote cache.
4. A method according to claim 3, wherein said performing a cache operation on said cache corresponding to said configuration attributes according to each of said configuration attributes comprises:
determining a target cache corresponding to each cache annotation according to the cache type field of each cache annotation;
and executing the cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation.
5. The method according to claim 4, wherein the cache annotation is a concurrent load protection annotation, a configuration attribute of the concurrent load protection annotation is a cache key value, and the performing, according to the configuration attribute of each cache annotation, a cache operation corresponding to the configuration attribute on the target cache includes:
And executing data loading operation on the cache content in the target cache based on a single thread according to the cache key value of the concurrent loading protection annotation.
6. The method according to claim 4, wherein the cache annotation is an auto-refresh cache annotation, a configuration attribute of the auto-refresh annotation is a refresh condition, and the performing a cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation comprises:
and at the target cache, refreshing the content meeting the refreshing condition in the target cache.
7. The method according to claim 4, wherein the cache annotation is a random expiration time annotation, the configuration attribute of the random expiration time annotation is a random expiration condition, and the performing the cache operation corresponding to the configuration attribute on the target cache according to the configuration attribute of each cache annotation comprises:
and at the target cache, clearing the content with the storage time meeting the random expiration condition in the target cache.
8. The method of claim 4, wherein the cache notes are NULL value cache expiration time notes, configuration attributes of the NULL value cache expiration time notes are NULL value expiration conditions, and the performing a cache operation corresponding to the configuration attributes on the target cache according to the configuration attributes of each cache note comprises:
And at the target cache, clearing the null content with the storage time meeting the null expiration condition in the target cache.
9. The method according to claim 2, wherein the method further comprises:
and starting a cache configuration function of the electronic equipment and setting the target path.
10. A cache access apparatus, the apparatus comprising:
the receiving module is used for receiving a cache configuration instruction, and the cache configuration instruction is used for configuring the cache of the electronic equipment;
the response module is used for responding to the cache configuration instruction and acquiring a cache annotation set corresponding to the cache, wherein the cache annotation set comprises one or more of concurrent loading protection annotation, automatic refreshing cache annotation, random expiration time annotation, automatic refreshing filtering annotation and NULL value cache expiration time annotation;
the analysis module is used for analyzing the cache annotation set to obtain the configuration attribute of each cache annotation in the cache annotation set;
and the execution module is used for executing the cache operation corresponding to the configuration attribute on the cache according to each configuration attribute.
11. A computer readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements the method according to any one of claims 1 to 9.
CN202310404824.4A 2023-04-14 2023-04-14 Cache access method and device, equipment and storage medium Pending CN116450966A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310404824.4A CN116450966A (en) 2023-04-14 2023-04-14 Cache access method and device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310404824.4A CN116450966A (en) 2023-04-14 2023-04-14 Cache access method and device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116450966A true CN116450966A (en) 2023-07-18

Family

ID=87125115

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310404824.4A Pending CN116450966A (en) 2023-04-14 2023-04-14 Cache access method and device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116450966A (en)

Similar Documents

Publication Publication Date Title
US10540279B2 (en) Server-based persistence management in user space
US9680954B2 (en) System and method for providing virtual desktop service using cache server
KR102236419B1 (en) Method, apparatus, device and storage medium for managing access request
US10915498B2 (en) Dynamically managing a high speed storage tier of a data storage system
WO2018164975A1 (en) Indexing a trace by insertion of reverse lookup data structures
US9483523B2 (en) Information processing apparatus, distributed processing system, and distributed processing method
US8700864B2 (en) Self-disabling working set cache
CN103150225B (en) Disk full abnormity fault tolerance method of object parallel storage system based on application level agent
US10402333B2 (en) Computer system including plurality of types of memory devices and method
US10747773B2 (en) Database management system, computer, and database management method
CN111026333A (en) Access request processing method, processing device, electronic equipment and storage medium
US9442790B2 (en) Computer and dumping control method
CN116450966A (en) Cache access method and device, equipment and storage medium
CN109492020A (en) A kind of data cache method, device, electronic equipment and storage medium
US11093169B1 (en) Lockless metadata binary tree access
CN114443722A (en) Cache management method and device, storage medium and electronic equipment
US20180285004A1 (en) Dynamically reacting to events within a data storage system
JP7173165B2 (en) History management device, history management method and program
KR102403063B1 (en) Mobile device and management method of mobile device
CN112948336A (en) Data acceleration method, cache unit, electronic device and storage medium
CN112732542A (en) Information processing method, information processing device and terminal equipment
CN117093158B (en) Storage node, system and data processing method and device of distributed storage system
CN116842299B (en) Dynamic data access risk control system and method
CN113407504B (en) Data processing method, user space file system and storage medium
US11842085B1 (en) Up-sized cluster performance modeling for a tiered data processing service

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination