Cache adjustment method and device, server and storage medium
By monitoring cache hit rate and eviction events, cache downgrade is achieved, and the problem of local cache overflow is solved, ensuring the stability of application services and protecting data privacy.
Patent Information
- Application Number
- CN202411503558.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-25
AI Technical Summary
Too large amount of local cached data causes cache overflow and cannot be cached downgraded in time, resulting in abnormal application services.
By monitoring cache hit rate and cache entry eviction events, adjust the cache policy. If the hit rate is lower than the preset threshold or the eviction event meets the conditions, start cache downgrade and cache requested data to the secondary cache.
It effectively avoids local cached data overflow, prevents application service exceptions, and protects private data through whitelisting and blacklisting mechanisms to prevent data leakage.
Smart Images

Figure CN119484640A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of data processing technology and financial technology, and in particular to a cache adjustment method, device, server and storage medium. Background Art
[0002] The application services of the financial system are characterized by large business volume and large request volume, so the cache of application services is a key technology to ensure the smooth operation of the financial system. Application services usually store and read request data through local cache and public cache. However, the storage capacity of the local cache is limited by the memory space of the application service. Therefore, when the cache continues to increase due to business growth and other behaviors and exceeds the memory space, it may cause the application service to be disconnected or abnormal. At this time, cache downgrade is required to change the request data that originally needs to be stored in the local cache to be stored in the public cache. The existing technology usually caches the request data by category, but it cannot solve the problem that when the amount of request data corresponding to the local cache is too large, the cache cannot be downgraded in time, resulting in local cache overflow. Summary of the invention
[0003] The present invention provides a cache adjustment method, device, server and storage medium, the main purpose of which is to provide a method for cache adjustment based on cache hit rate and cache entry eviction events to solve the technical problem of application service abnormality caused by data overflow in local cache.
[0004] To achieve the above object, the present invention provides a cache adjustment method, the method comprising:
[0005] Creating a first-level cache in the application service, and creating a second-level cache in the server where the application service is located;
[0006] Obtaining a first-level cache hit rate of the request data of the application service through cache statistical information records, generating a first-level cache warning notification of the application service and sending it to a server backend corresponding to the application service when the first-level cache hit rate is less than a first threshold, and starting a first-level cache downgrade operation when the first-level cache hit rate is less than a second threshold, caching the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;
[0007] Monitor the cache entry eviction event of the first-level cache, determine whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache to cache the request data to be cached into the second-level cache;
[0008] Obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set whitelist and blacklist respectively, cache the request data that matches the user identifier or the cache key in the whitelist into the first-level cache, if the user identifier or the cache key is matched in the blacklist, reject the corresponding request data cache, generate a blacklist cache warning notification and send it to the server backend corresponding to the application service.
[0009] In order to solve the above problem, the present invention further provides a cache adjustment device, the cache adjustment device comprising:
[0010] A cache creation module, used to create a first-level cache in the application service and create a second-level cache in the server where the application service is located;
[0011] A hit rate judgment module, used to obtain the first-level cache hit rate of the request data of the application service through cache statistical information records, and when the first-level cache hit rate is less than a first threshold, generate a first-level cache warning notification of the application service and send it to the server backend corresponding to the application service, and when the first-level cache hit rate is less than a second threshold, start the first-level cache downgrade operation, and cache the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;
[0012] an eviction event judgment module, used to monitor the cache entry eviction event of the first-level cache, judge whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache, and cache the request data to be cached into the second-level cache;
[0013] The black and white list matching module is used to obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set white list and black list respectively, and cache the request data that matches the user identifier or the cache key in the white list into the first-level cache. If the user identifier or the cache key is matched in the black list, the corresponding request data cache is rejected, and a blacklist cache warning notification is generated and sent to the server background corresponding to the application service.
[0014] In order to solve the above problem, the present invention further provides a server, the server comprising:
[0015] at least one processor; and,
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the cache adjustment method as described above.
[0018] In order to solve the above problem, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the cache adjustment method described above is implemented.
[0019] The present invention adjusts the cache of request data by comparing the cache hit rate and a preset threshold, and confirms whether to perform cache downgrade by monitoring the cache entry eviction event of the first-level cache, so as to avoid data overflow in the local cache and cause application service abnormality. By configuring the cache of specified request data through black and white lists, it can ensure that the privacy data of the application service will not be cached in the public cache and cause data leakage, and at the same time identify abnormal requests to prevent abnormal data from polluting the cache. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0021] Figure 1 is a schematic diagram of an application environment of a cache adjustment method in one embodiment of the present invention;
[0022] Figure 2 is a flow chart of a cache adjustment method in one embodiment of the present invention;
[0023] Figure 3 is a first structural diagram of a server in a first embodiment of the present invention;
[0024] Figure 4 is a second structural diagram of a server in a second embodiment of the present invention;
[0025] Figure 5 It is a structural schematic diagram of a cache adjustment device in one embodiment of the present invention.
[0026] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the present invention more clear, the principle and spirit of the present invention will be described below with reference to several specific embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.
[0028] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. In addition, the technical solutions between each embodiment can be combined with each other, but it must be based on the ability of ordinary technicians in this field to implement. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0029] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.
[0030] The phrases such as "one embodiment" or "some embodiments" described in the present application mean that the specific features, structures or characteristics described in the embodiment are included in one or more embodiments of the present application. Therefore, the phrases such as "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments" that appear in the differences in the present application do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. In addition, the terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0031] The cache adjustment method provided by the embodiment of the present invention can be applied in Figure 1In an application environment, the client communicates with the server through a network. The server can create a first-level cache in the application service and a second-level cache in the server; obtain the first-level cache hit rate of the request data of the application service through cache statistical information records, generate a first-level cache warning notification of the application service when the first-level cache hit rate is less than a first threshold, and start the downgrade operation of the first-level cache when the first-level cache hit rate is less than a second threshold, and cache the request data to be cached to the second-level cache, wherein the first threshold is greater than the second threshold; monitor the cache entry eviction event of the first-level cache, determine whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache, and cache the request data to be cached to the second-level cache; obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the preset white list and black list respectively, cache the request data matched with the user identifier or the cache key in the white list to the first-level cache, and if the user identifier or the cache key is matched in the black list, refuse the corresponding request data cache, and generate a blacklist cache warning notification. In the present invention, by comparing the cache hit rate and the preset threshold to adjust the cache of the request data, and by monitoring the cache entry eviction event of the first-level cache to confirm whether to perform cache downgrade, it is possible to avoid data overflow in the local cache causing application service abnormalities, and by configuring the cache of the specified request data through the black and white lists, it is possible to ensure that the privacy data of the application service will not be cached in the public cache to cause data leakage, and at the same time identify abnormal requests to prevent abnormal data from polluting the cache. Among them, the client can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers. The present invention is described in detail below through specific embodiments.
[0032] like Figure 2 FIG. 4 is a flow chart of an embodiment of a cache adjustment method of the present invention. The cache adjustment method is applied to a server and includes steps S1-S4.
[0033] S1. Create a first-level cache in an application service, and create a second-level cache in a server where the application service is located.
[0034] In one embodiment, the step of creating a first-level cache in an application service and creating a second-level cache in a server where the application service is located includes:
[0035] Creating a local cache in a local process of the application service, and using the local cache as a first-level cache of the application service;
[0036] A distributed cache is created outside the local process of the application service, and the distributed cache is used as a secondary cache of the application service.
[0037] In one embodiment, the first-level cache is a local cache of the application service, which is only used by the application service for data caching and reading, such as the caffeine local cache; the second-level cache is a public cache of the server where the application service is located, which can be used for data caching and reading by all application services in the server, such as the redis distributed cache. There is usually a large amount of private data that needs to be kept confidential in the financial system, such as bank account passwords. When storing private data, financial application services usually choose to store the private data in a local cache that is only used by the application service itself for data storage and reading, rather than a public cache that can be used by other application services on the same server, to prevent the leakage of private data.
[0038] S2. Obtain the first-level cache hit rate of the request data of the application service through cache statistical information records; when the first-level cache hit rate is less than a first threshold, generate a first-level cache warning notification for the application service and send it to the server backend corresponding to the application service; when the first-level cache hit rate is less than a second threshold, start the first-level cache downgrade operation, and cache the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold.
[0039] Specifically, the cache statistical information record is the local cache statistical information contained in the log of the application service, the first-level cache hit rate is the ratio of the number of cache hits to the number of local cache queries, the number of cache hits is the number of times the requested data is successfully obtained from the local cache based on the request, and the local cache query number is the number of times the requested data is queried from the local cache based on the request.
[0040] In one embodiment, the first threshold and the second threshold are updated through the distributed configuration center of the application service. The distributed configuration center may be an Apollo configuration center, which is an open source distributed configuration center mainly used for unified management of configuration information in a microservice architecture. The basic steps of using the Apollo configuration center include:
[0041] 1. Introduce Apollo client dependency;
[0042] 2. Configure Apollo information in application.properties or application.yml;
[0043] 3. Use the @Value annotation or @Configuration Properties annotation to obtain configuration information.
[0044] In one embodiment, obtaining the first-level cache hit rate of the request data of the application service through cache statistical information records includes:
[0045] When the application service is started, the cache statistical information record in the log of the application service is obtained through the statistical function of the preset cache tool in the first-level cache;
[0046] A first-level cache hit rate of the request data of the application service is obtained from the cache statistical information record.
[0047] In one embodiment, when the first-level cache is a caffeine local cache, the statistical function of the preset cache tool enables the cache statistical information recording of the application service through the record Stats() method, and returns the hit rate of the application service's request in the first-level cache through the hitRate() method.
[0048] For example, the first threshold configured by the distributed configuration center is 0.8, and the second threshold is 0.7. When the cache hit rate of the cache is 0.85 based on the statistical function acquisition request of the preset cache tool in the local cache, it is judged that the first-level cache hit rate is greater than the first threshold; when the cache hit rate of the cache is 0.75 based on the statistical function acquisition request of the preset cache tool in the local cache, it is judged that the first-level cache hit rate is less than the first threshold and greater than the second threshold, and a first-level cache warning notification of the application service is generated and sent to the server backend corresponding to the application service, so that the administrator of the server backend can perform local cache cleanup or manual downgrade; when the cache hit rate of the cache is 0.65 based on the statistical function acquisition request of the preset cache tool in the local cache, it is judged that the first-level cache hit rate is less than the second threshold, and the downgrade operation of the first-level cache is automatically started, and the request data that needs to be cached in the application later is changed to cache in the second-level cache.
[0049] In another embodiment, when the preset cache tool is a Guava cache tool, the cache statistics record of the application service is obtained through the Cache Stats object. The Cache Stats object provides access to statistical information such as cache hit rate, number of loaded cache items, number of cache item recycles, etc., which can be obtained through the Cache.stats() method, where the hitCount attribute is the number of cache hits, which is used to indicate the number of times data is successfully obtained from the cache.
[0050] The cache hit rate refers to the ratio of the number of times data is successfully retrieved from the cache to the total number of requests. Simply put, if a data request finds the required data in the cache, then this request is considered a "hit", otherwise it is a "miss". The cache hit rate is an important indicator for measuring the effectiveness of the cache, usually expressed as a percentage.
[0051] The cache hit rate is affected by many factors, including: 1. The size of the cache key set: the larger the amount of data stored in the cache, the higher the hit rate. 2. The size of the memory space: the larger the cache capacity, the more data can be stored, thereby improving the hit rate. 3. The life of the cache: the longer the validity period of the cached data, the higher the probability of repeated access, thereby improving the hit rate. 4. Application scenario: different application scenarios have different requirements for cache, for example, OLTP and OLAP applications have different requirements for cache. 5. Cache granularity: the smaller the cache granularity, the higher the hit rate. 6. Architectural design: reasonable architectural design can avoid cache failure and improve the hit rate. 7. Cache capacity and validity period: too small a cache capacity and too short a validity period will reduce the hit rate.
[0052] In one embodiment, after obtaining the first-level cache hit rate of the request data of the application service through the cache statistical information record, the method further includes:
[0053] When the first-level cache hit rate is greater than a first threshold, detecting whether the available cache space of the first-level cache is less than a preset available cache space threshold;
[0054] If the available cache space of the first-level cache is less than the preset available cache space threshold, the downgrade operation of the first-level cache is initiated, the request data that needs to be cached is cached to the second-level cache, and a first-level cache warning notification of the application service is generated and sent to the server background corresponding to the application service.
[0055] In one embodiment, after the initiation of the downgrade operation of the first-level cache, the method further includes:
[0056] Detecting available cache space and a hit rate of the first-level cache of the first-level cache;
[0057] If the available cache space of the first-level cache is greater than a preset available cache space threshold, and the first-level cache hit rate is greater than a first threshold, request data that needs to be cached subsequently in the application is changed to be cached in the first-level cache again.
[0058] In this embodiment, after cache downgrading according to the cache hit rate of the requested data, the data cache can be changed back to prioritize local cache according to the available storage space of the first-level cache and the cache hit rate of the requested data, thereby realizing dynamic cache adjustment to avoid wasting memory space in the local cache.
[0059] Cache downgrade refers to discarding some unimportant cache data according to a certain strategy to ensure the normal operation of the system when system resources are limited or cache space is insufficient. Common reasons for cache downgrade include insufficient system resources, full cache space, etc. Cache downgrade can prevent cache space from being full and causing cache failure or performance degradation. In this embodiment, cache downgrade of multi-level cache refers to caching request data in a public secondary cache when the local primary cache space is insufficient.
[0060] Cache demotion can be achieved in the following ways:
[0061] 1. Degradation based on access frequency: Degrade according to the access frequency of the data; 2. Degradation based on storage duration: Degrade according to the storage duration of the data in the cache; 3. Degradation based on data importance: Degrade according to the importance of the data.
[0062] In this embodiment, cache downgrade is performed according to the cache hit rate of the first-level cache, which is a downgrade based on access frequency, that is, the access frequency of the cache is judged according to the number of times the cache data is successfully obtained from the cache, and the cache is downgraded according to the cache data access frequency of the first-level cache.
[0063] S3. Monitor the cache entry eviction event of the first-level cache, determine whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache, and cache the request data that needs to be cached into the second-level cache.
[0064] In one embodiment, monitoring a cache entry eviction event of the first-level cache and determining whether the cache entry eviction event satisfies a preset condition includes:
[0065] Performing event monitoring on a cache entry eviction method of a preset cache tool in the first-level cache to obtain eviction event statistics;
[0066] The eviction reason of each cache entry is obtained according to the eviction event statistical information. If the eviction reason is insufficient memory, it is determined that the cache entry eviction event meets a preset condition.
[0067] Cache eviction is the process of deleting data from the cache to make room for new entries when the cache capacity reaches its limit. It is sometimes triggered by cache invalidation, that is, deleting data from the cache that is no longer considered valid or fresh. A cache entry eviction event refers to a record of data being deleted from the cache, which is obtained from the cache log file through a preset cache tool. The following eviction strategies are usually used in the cache: 1. Cache eviction occurs when the memory limit is reached and the client attempts to execute a command that may result in more memory usage. 2. Delete cache data that has been used less recently to make room for newly added data. 3. Delete cache data that contains an expiration date and has expired according to the expiration time to make room for newly added data. 4. Randomly delete cache data to make room for newly added data. 5. Randomly delete cache data with an expiration time set to make room for newly added data. The cache entry eviction events corresponding to the above eviction strategies are represented by different eviction reasons. In this embodiment, "the eviction reason is insufficient memory" is eviction strategy 1.
[0068] In one embodiment, when the first-level cache is a caffeine local cache, the statistical function of the preset cache tool monitors cache entry eviction events through the eviction Listener eviction method, and counts the monitored cache entry eviction events. For example, if the value of the eviction reason in a cache entry eviction event is SIZE, it means that the cache entry is cleared due to limited cache space size and limited total weight, then it is judged that the cache entry eviction event meets the preset conditions.
[0069] In another embodiment, when the preset cache tool is the Guava cache tool, the Removal Listener object is set for the cache through the CacheBuilder.removal Listener() method to obtain the RemovalNotification class in Guava used to indicate the notification that the cache item has been removed. After the Removal Listener is registered in the Guava Cache, the Removal Notification object will be passed to the on Removal method of the RemovalListener when the cache item is removed. RemovalNotification contains some important information about the removed cache item, such as the key, value, and removal reason, where get Cause() means getting the removal reason, which is an enumeration type Removal Cause parameter, indicating the reason why the cache item was removed. The optional values of Removal Cause include: 1. EXPLICIT: The entry is explicitly deleted, for example, by calling the Cache.invalidate(key) method. 2. REPLACED: The entry is replaced, for example, by calling the Cache.put(key,value) method to repeatedly put the same key. 3. EXPIRED: The cache entry is removed because it has reached the specified expiration time. 4. SIZE: The cache entry was removed because it exceeded the specified size limit. 5. COLLECTED: The cache entry was removed by garbage collection. This occurs when weak references or soft references to cache values are enabled. In this embodiment, the optional value corresponding to the cache entry eviction event that meets the preset conditions is SIZE.
[0070] In this embodiment, by monitoring and counting cache entry eviction events, it is possible to determine whether the local cache has performed cache cleanup due to insufficient memory based on the commonly used cache eviction strategy, thereby determining whether the memory space of the local cache is sufficient, and downgrading the cache when the local cache memory space is insufficient, thereby avoiding data overflow in the local cache and causing application service abnormalities.
[0071] S4. Obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set whitelist and blacklist respectively, cache the request data that matches the user identifier or the cache key in the whitelist into the first-level cache, and if the user identifier or the cache key is matched in the blacklist, reject the corresponding request data cache, generate a blacklist cache warning notification and send it to the server backend corresponding to the application service.
[0072] In one embodiment, the cache adjustment method further includes:
[0073] Obtaining a security user identifier and a security cache key through a whitelist setting interface of a distributed configuration center of the application service;
[0074] Storing the secure user identifier and the secure cache key in a preset whitelist;
[0075] Obtaining an abnormal user identifier and an abnormal cache key in the log of the application service;
[0076] The abnormal user identifier and the abnormal cache key are stored in a preset blacklist.
[0077] In one embodiment, the blacklist and the whitelist are configured and updated through the distributed configuration center of the application service. The whitelist is configured through the whitelist setting interface of the distributed configuration center of the application service, and the blacklist is updated and configured in real time by monitoring abnormal events in the log of the application service, such as the cache key of abnormal data in the cache entry eviction event where the eviction reason is abnormal data. Specifically, the whitelist includes a pre-set user identifier and cache key for a specified local storage, and the blacklist includes an abnormal user identifier and cache key updated when the application service is running.
[0078] In one embodiment, obtaining the user identifier and cache key corresponding to the request data of the application service includes:
[0079] Obtaining request data for the application service;
[0080] Identify a user ID corresponding to the client sending the request data;
[0081] A cache key of the request data that needs to be cached is identified from the request data.
[0082] In one embodiment, the cache adjustment method further includes:
[0083] When receiving a request from a client to access the application service, obtaining a user identification of the client and matching it with a preset whitelist and blacklist respectively;
[0084] If the user identifier is matched in the whitelist, the client is allowed to access the application service and use the first-level cache for data storage and data access;
[0085] If the user identifier is matched in the blacklist, the client is prohibited from accessing the application service, and a blacklist cache warning notification is generated and sent to the server backend corresponding to the application service;
[0086] If the user identifier is not matched in the whitelist and the blacklist, the client is allowed to access the application service, and when the application service does not perform cache downgrade, the first-level cache is used for data storage and data access; when the application service performs cache downgrade, the second-level cache is used for data storage and data access.
[0087] The strategies and specific operations of cache downgrade include: 1. Setting up early warning mechanism: Setting graded early warnings according to logs, and downgrading cache services when a certain early warning is reached; 2. Combining automatic downgrade with manual downgrade: The system can automatically downgrade based on some key data, and switches can also be configured for manual downgrade; 3. Emergency handling of serious errors: For serious errors, urgent manual downgrade is required, and email warnings of serious errors are sent.
[0088] In this embodiment, the cache of the request data is adjusted by comparing the cache hit rate with a preset threshold. The hit rate of the first-level cache is read according to the log. When the hit rate is lower than the preset threshold, an early warning is triggered and the cache is downgraded. The cache entry eviction events of the first-level cache are monitored to confirm whether to downgrade the cache. The cache is automatically downgraded according to the event type of the monitored event. The cache of the specified request data is configured through the black and white lists, which is a configuration for caching the request data itself.
[0089] In this embodiment, by configuring a whitelist to specify data stored in the local cache, the private data of the application service can be fixedly stored in the local cache of the application service, avoiding the leakage of application service data caused by the private data being mistakenly stored in the public cache due to cache degradation. By configuring a blacklist to identify abnormal cache data, such as data uploaded by abnormal users (based on abnormal user identification) or data with abnormal content (based on abnormal cache key identification), the abnormal cache data is refused to be stored in the local cache or the public cache, which can prevent abnormal data from polluting the cache space.
[0090] It can be seen from the above embodiments that the embodiments of the present invention adjust the cache of request data by comparing the cache hit rate and the preset threshold, and confirm whether to perform cache downgrade by monitoring the cache entry eviction events of the first-level cache, so as to avoid data overflow in the local cache and cause application service abnormalities. By configuring the cache of specified request data through black and white lists, it can ensure that the privacy data of the application service will not be cached in the public cache and cause data leakage, and at the same time identify abnormal requests to prevent abnormal data from polluting the cache.
[0091] like Figure 3FIG. 1 is a schematic diagram of a first embodiment of a server of the present invention. Server 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The server 1 can be a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer consisting of a group of loosely coupled computer sets.
[0092] In this embodiment, the server 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 that can be interconnected and communicated via a system bus. The memory 11 stores a cache adjustment program 10 that can be executed by the processor 12. Figure 3 Only the server 1 having components 11-13 and the cache adjustment program 10 is shown. It can be understood by those skilled in the art that Figure 3 The structure shown does not constitute a limitation on the server 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0093] The memory 11 includes a memory and at least one type of readable storage medium. The memory provides a cache for the operation of the server 1; the readable storage medium may be volatile or non-volatile. Specifically, the readable storage medium may be a storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the readable storage medium may be an internal storage unit of the server 1, such as a hard disk of the server 1; in other embodiments, the storage medium may also be an external storage device of the server 1, such as a plug-in hard disk equipped on the server 1, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. In this embodiment, the readable storage medium of the memory 11 mainly includes a program storage area and a data storage area, wherein the program storage area is generally used to store an operating system and various application software installed on the server 1, such as storing the code of the cache adjustment program 10 in an embodiment of the present invention; the data storage area can store data created according to the use of the blockchain node, such as various types of data that have been output or are to be output.
[0094] The processor 12 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 12 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect each component of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing resource dynamic scheduling programs, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data. The processor 12 is generally used to control the overall operation of the server 1, such as executing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the cache adjustment program 10, etc.
[0095] The network interface 13 may include a wireless network interface or a wired network interface.
[0096] like Figure 4 , which is a schematic diagram of a second embodiment of the server of the present invention. The server 1 may also include a user interface 14, which may include a display (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 14 may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (Organic Light-Emitting Diode, OLED) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the server 1 and to display a visual user interface.
[0097] In one embodiment of the present invention, when the cache adjustment program 10 is executed by the processor 12, the cache adjustment method is implemented as follows, including steps S1-S4:
[0098] S1. Create a first-level cache in the application service, and create a second-level cache in the server where the application service is located;
[0099] S2. Obtaining the first-level cache hit rate of the request data of the application service through the cache statistical information record; when the first-level cache hit rate is less than a first threshold, generating a first-level cache warning notification of the application service and sending it to the server backend corresponding to the application service; when the first-level cache hit rate is less than a second threshold, starting the first-level cache downgrade operation, caching the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;
[0100] S3, monitoring the cache entry eviction event of the first-level cache, determining whether the cache entry eviction event meets a preset condition, and if the cache entry eviction event meets the preset condition, starting the downgrade operation of the first-level cache, caching the request data to be cached into the second-level cache;
[0101] S4. Obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set whitelist and blacklist respectively, cache the request data that matches the user identifier or the cache key in the whitelist into the first-level cache, and if the user identifier or the cache key is matched in the blacklist, reject the corresponding request data cache, generate a blacklist cache warning notification and send it to the server backend corresponding to the application service.
[0102] The specific operation steps implemented by the above steps S1-S4 are substantially the same as the steps S1-S4 of the first embodiment of the cache adjustment method of the present invention, and will not be repeated here.
[0103] In other embodiments, the cache adjustment program 10 can also be divided into one or more modules, one or more modules are stored in the memory 11, and are executed by one or more processors (processor 12 in this embodiment) to complete the present invention. The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions, and is used to describe the execution process of the cache adjustment program 10 in the server 1.
[0104] like Figure 5 , which is a schematic diagram of the structure of a cache adjustment device provided in one embodiment of the present invention.
[0105] In the first embodiment of the present invention, the cache adjustment device 100 includes a cache creation module 110, a hit rate determination module 120, an eviction event determination module 130, and a blacklist and whitelist matching module 140. Exemplarily:
[0106] The cache creation module 110 is used to create a first-level cache in the application service and create a second-level cache in the server where the application service is located;
[0107] The hit rate judgment module 120 is used to obtain the first-level cache hit rate of the request data of the application service through the cache statistical information record, and when the first-level cache hit rate is less than a first threshold, generate a first-level cache warning notification of the application service and send it to the server backend corresponding to the application service, and when the first-level cache hit rate is less than a second threshold, start the first-level cache downgrade operation, and cache the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;
[0108] The eviction event judgment module 130 is used to monitor the cache entry eviction event of the first-level cache, judge whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache to cache the request data to be cached into the second-level cache;
[0109] The black and white list matching module 140 is used to obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set white list and black list respectively, and cache the request data that matches the user identifier or the cache key in the white list into the first-level cache. If the user identifier or the cache key is matched in the black list, the corresponding request data cache is rejected, and a blacklist cache warning notification is generated and sent to the server backend corresponding to the application service.
[0110] In one embodiment, the cache creation module 110 is specifically configured to:
[0111] Creating a local cache in a local process of the application service, and using the local cache as a first-level cache of the application service;
[0112] A distributed cache is created outside the local process of the application service, and the distributed cache is used as a secondary cache of the application service.
[0113] In one embodiment, the hit rate determination module 120 is specifically configured to:
[0114] When the application service is started, the cache statistical information record in the log of the application service is obtained through the statistical function of the preset cache tool in the first-level cache;
[0115] A first-level cache hit rate of the request data of the application service is obtained from the cache statistical information record.
[0116] In one embodiment, the hit rate determination module 120 is specifically configured to:
[0117] When the first-level cache hit rate is greater than a first threshold, detecting whether the available cache space of the first-level cache is less than a preset available cache space threshold;
[0118] If the available cache space of the first-level cache is less than the preset available cache space threshold, the downgrade operation of the first-level cache is initiated, the request data that needs to be cached is cached to the second-level cache, and a first-level cache warning notification of the application service is generated and sent to the server background corresponding to the application service.
[0119] In one embodiment, the hit rate determination module 120 is specifically configured to:
[0120] Detecting available cache space and a hit rate of the first-level cache of the first-level cache;
[0121] If the available cache space of the first-level cache is greater than a preset available cache space threshold, and the first-level cache hit rate is greater than a first threshold, request data that needs to be cached subsequently in the application is changed to be cached in the first-level cache again.
[0122] In one embodiment, the eviction event determination module 130 is specifically configured to:
[0123] Performing event monitoring on a cache entry eviction method of a preset cache tool in the first-level cache to obtain eviction event statistics;
[0124] The eviction reason of each cache entry is obtained according to the eviction event statistical information. If the eviction reason is insufficient memory, it is determined that the cache entry eviction event meets a preset condition.
[0125] In one embodiment, the blacklist and whitelist matching module 140 is specifically used to:
[0126] Obtaining a security user identifier and a security cache key through a whitelist setting interface of a distributed configuration center of the application service;
[0127] Storing the secure user identifier and the secure cache key in a preset whitelist;
[0128] Obtaining an abnormal user identifier and an abnormal cache key in the log of the application service;
[0129] The abnormal user identifier and the abnormal cache key are stored in a preset blacklist.
[0130] In one embodiment, the blacklist and whitelist matching module 140 is specifically used to:
[0131] When receiving a request from a client to access the application service, obtaining a user identification of the client and matching it with a preset whitelist and blacklist respectively;
[0132] If the user identifier is matched in the whitelist, the client is allowed to access the application service and use the first-level cache for data storage and data access;
[0133] If the user identifier is matched in the blacklist, the client is prohibited from accessing the application service, and a blacklist cache warning notification is generated and sent to the server backend corresponding to the application service;
[0134] If the user identifier is not matched in the whitelist and the blacklist, the client is allowed to access the application service, and when the application service does not perform cache downgrade, the first-level cache is used for data storage and data access; when the application service performs cache downgrade, the second-level cache is used for data storage and data access.
[0135] For the specific definition of the cache adjustment device, please refer to the definition of the cache adjustment method above, which will not be repeated here. Each module in the above-mentioned cache adjustment device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0136] In addition, the embodiment of the present invention further proposes a computer-readable storage medium, which can be volatile or non-volatile. Specifically, the computer-readable storage medium can be any one or any combination of a hard disk, a multimedia card, an SD card, a flash memory card, an SMC, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, etc. The computer-readable storage medium stores a cache adjustment program.
[0137] The specific software function implementation of the computer-readable storage medium of the present invention is substantially the same as the specific software implementation in the above-mentioned server 1, and will not be described in detail here.
[0138] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0139] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.
[0140] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the method described in each embodiment of the present invention.
[0141] The above are only preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the present invention and the drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention. It should be noted that if software tools or components other than our company appear in the embodiments of this application, they are only used for example introduction and do not represent actual use.
Claims
1. A cache adjustment method, characterized in that: The method comprises: Creating a first-level cache in the application service, and creating a second-level cache in the server where the application service is located; Obtaining a first-level cache hit rate of the request data of the application service through cache statistical information records, generating a first-level cache warning notification of the application service and sending it to a server backend corresponding to the application service when the first-level cache hit rate is less than a first threshold, and starting a first-level cache downgrade operation when the first-level cache hit rate is less than a second threshold, caching the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold; Monitor the cache entry eviction event of the first-level cache, determine whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache to cache the request data to be cached into the second-level cache; Obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set whitelist and blacklist respectively, cache the request data that matches the user identifier or the cache key in the whitelist into the first-level cache, if the user identifier or the cache key is matched in the blacklist, reject the corresponding request data cache, generate a blacklist cache warning notification and send it to the server backend corresponding to the application service.
2. The cache adjustment method according to claim 1, characterized in that: The step of creating a first-level cache in the application service and creating a second-level cache in the server where the application service is located includes: Creating a local cache in a local process of the application service, and using the local cache as a first-level cache of the application service; A distributed cache is created outside the local process of the application service, and the distributed cache is used as a secondary cache of the application service.
3. The cache adjustment method according to claim 1, characterized in that: The obtaining the first-level cache hit rate of the request data of the application service through the cache statistical information record includes: When the application service is started, the cache statistical information record in the log of the application service is obtained through the statistical function of the preset cache tool in the first-level cache; A first-level cache hit rate of the request data of the application service is obtained from the cache statistical information record.
4. The cache adjustment method according to claim 1, characterized in that: After obtaining the first-level cache hit rate of the request data of the application service through the cache statistical information record, the method further includes: When the first-level cache hit rate is greater than a first threshold, detecting whether the available cache space of the first-level cache is less than a preset available cache space threshold; If the available cache space of the first-level cache is less than the preset available cache space threshold, the downgrade operation of the first-level cache is initiated, the request data that needs to be cached is cached to the second-level cache, and a first-level cache warning notification of the application service is generated and sent to the server background corresponding to the application service.
5. The cache adjustment method according to claim 1, characterized in that: The monitoring of the cache entry eviction event of the first-level cache and determining whether the cache entry eviction event satisfies a preset condition includes: Performing event monitoring on a cache entry eviction method of a preset cache tool in the first-level cache to obtain eviction event statistics; The eviction reason of each cache entry is obtained according to the eviction event statistical information. If the eviction reason is insufficient memory, it is determined that the cache entry eviction event meets a preset condition.
6. The cache adjustment method according to claim 1, characterized in that: The obtaining of the user identifier and cache key corresponding to the request data of the application service includes: Obtaining request data for the application service; Identify a user ID corresponding to the client sending the request data; A cache key of the request data that needs to be cached is identified from the request data.
7. The cache adjustment method according to claim 1, characterized in that: The cache adjustment method further includes: Obtaining a security user identifier and a security cache key through a whitelist setting interface of a server corresponding to the application service; Storing the secure user identifier and the secure cache key in a preset whitelist; Obtaining an abnormal user identifier and an abnormal cache key in the log of the application service; The abnormal user identifier and the abnormal cache key are stored in a preset blacklist.
8. A cache adjustment device, characterized in that: The cache adjustment device comprises: A cache creation module, used to create a first-level cache in the application service and create a second-level cache in the server where the application service is located; A hit rate judgment module, used to obtain the first-level cache hit rate of the request data of the application service through cache statistical information records, and when the first-level cache hit rate is less than a first threshold, generate a first-level cache warning notification of the application service and send it to the server backend corresponding to the application service, and when the first-level cache hit rate is less than a second threshold, start the first-level cache downgrade operation, and cache the request data that needs to be cached into the second-level cache, wherein the first threshold is greater than the second threshold; an eviction event judgment module, used to monitor the cache entry eviction event of the first-level cache, judge whether the cache entry eviction event meets the preset condition, and if the cache entry eviction event meets the preset condition, start the downgrade operation of the first-level cache, and cache the request data to be cached into the second-level cache; The black and white list matching module is used to obtain the user identifier and cache key corresponding to the request data of the application service, and match them in the pre-set white list and black list respectively, and cache the request data that matches the user identifier or the cache key in the white list into the first-level cache. If the user identifier or the cache key is matched in the black list, the corresponding request data cache is rejected, and a blacklist cache warning notification is generated and sent to the server background corresponding to the application service.
9. A server, characterized in that: The server comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the cache adjustment method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the cache adjustment method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data-caching method, device and system
CN103858112A
Cache-based processing method and device
CN110598138A
Method and device for optimizing distributed cache
CN111209308A
Data caching method and device, server and storage medium
CN117874083A
Data acquisition method based on local cache and distributed cache, and application server
WO2022022105A1