Cache adjustment method, device, server and storage medium

By creating first-level and second-level caches in the application service, combining cache hit rate and eviction events, and using whitelist and blacklist configurations, the problem of local cache overflow is solved, ensuring the stable operation of the application service and data security.

CN119484640BActive Publication Date: 2025-09-30CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411503558.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-09-30
Estimated Expiration
2044-10-25

AI Technical Summary

Technical Problem

Existing technologies cannot effectively solve the cache overflow problem caused by excessive local cache data volume, resulting in application service anomalies.

Method used

By creating a first-level cache and a second-level cache, using cache hit rate and cache entry eviction events to adjust the cache, combined with whitelist and blacklist configurations, dynamic cache adjustment and secure data storage can be achieved.

Benefits of technology

It avoids application service anomalies caused by local cache data overflow, ensures the privacy data security of application services, and prevents data leakage and cache pollution by abnormal data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119484640B_ABST
    Figure CN119484640B_ABST
Patent Text Reader

Abstract

The present invention relates to the fields of data processing technology and financial technology, and provides a cache adjustment method, comprising: creating a first-level cache in an application service and creating a second-level cache in a server; obtaining a first-level cache hit rate of request data through cache statistical information records, generating a first-level cache warning notification when the first-level cache hit rate is less than a first threshold, and initiating a first-level cache downgrade operation when the first-level cache hit rate is less than a second threshold; initiating a first-level cache downgrade operation when a cache entry eviction event of the first-level cache meets a preset condition; obtaining a user identifier and a cache key corresponding to the request data and obtaining a blacklist and whitelist, caching request data that matches the user identifier or cache key in the whitelist into the first-level cache, refusing to cache request data that matches the user identifier or cache key in the blacklist, and generating a blacklist cache warning notification. The cache adjustment method of the present invention can reduce the occurrence of data overflow in the local cache, leading to application service anomalies.
Need to check novelty before this filing date? Find Prior Art

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 volumes and large request volumes, so the cache of application services is a key technology to ensure the smooth operation of the financial system. Application services usually use local caches and public caches to store and read request data. However, the storage capacity of the local cache is limited by the memory space of the application service. Therefore, when business growth and other behaviors cause the cache to continue to grow and exceed 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 needed 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 downgrade cannot be performed 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 request data of the application service through cache statistical information records; 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 a server backend corresponding to the application service; and when the first-level cache hit rate is less than a second threshold, initiating a first-level cache demotion operation to cache the request data that needs to be cached into a second-level cache, wherein the first threshold is greater than the second threshold;

[0007] monitoring a cache entry eviction event of the first-level cache, determining whether the cache entry eviction event satisfies a preset condition, and if so, initiating a downgrade operation of the first-level cache to cache the requested data to 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, which includes:

[0010] A cache creation module, configured to create a first-level cache in the application service and a second-level cache in the server where the application service is located;

[0011] a hit rate determination module, configured to obtain a first-level cache hit rate of 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 a server backend corresponding to the application service; and when the first-level cache hit rate is less than a second threshold, initiate a first-level cache demotion operation to cache the request data to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;

[0012] an eviction event judgment module, configured to monitor cache entry eviction events of the first-level cache, judge whether the cache entry eviction events meet preset conditions, and if so, initiate a downgrade operation of the first-level cache to cache the requested data to the second-level cache;

[0013] The blacklist and whitelist 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 whitelist and blacklist respectively, and 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, 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, 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 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 events of the first-level cache. This can 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 private data of the application service will not be cached in the public cache and cause data leakage. At the same time, abnormal requests can be identified 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 following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0021] Figure 1 This is a schematic diagram of an application environment of a cache adjustment method according to an embodiment of the present invention;

[0022] Figure 2 This is a flow chart of a cache adjustment method according to an 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 diagram of a cache adjustment device in one embodiment of the present invention.

[0026] The realization of the objectives, 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 solutions and advantages of the present invention more clearly understood, the principles 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 herein are only used to explain the present invention and are not intended 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 intended to limit the present invention. Based on the embodiments of 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 a 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 merely 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, words such as “first” and “second” are used to distinguish between identical or similar items with basically the same functions and effects. Those skilled in the art can understand that words such as “first” and “second” do not limit the quantity and execution order, and words such as “first” and “second” do not necessarily limit them to be different.

[0030] The phrases "one embodiment" or "some embodiments" described in this application mean that the specific features, structures, or characteristics described in that embodiment are included in one or more embodiments of the application. Thus, the phrases "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" that appear in different places in this application do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. In addition, the terms "including," "comprising," "having," and their variations all mean "including but not limited to," unless otherwise specifically emphasized.

[0031] The cache adjustment method provided by the embodiment of the present invention can be applied in Figure 1In an application environment, wherein a client communicates with a server via a network, the server may create a first-level cache in the application service and a second-level cache in the server; obtain a first-level cache hit rate of request data of the application service through cache statistics 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; when the first-level cache hit rate is less than a second threshold, initiate a first-level cache demotion operation, caching the request data to be cached to the second-level cache, wherein the first threshold is greater than the second threshold; monitor cache entry eviction events of the first-level cache, determine whether the cache entry eviction events meet a preset condition, and if so, initiate a first-level cache demotion operation, caching the request data to be cached to the second-level cache; obtain a user identifier and a cache key corresponding to the request data of the application service, and match them against a preset whitelist and blacklist, respectively; cache the request data that matches the user identifier or cache key in the whitelist in the first-level cache; and if the user identifier or cache key matches the user identifier or cache key in the blacklist, refuse to cache the corresponding request data 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, causing 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, tablets and portable wearable devices. The server can be implemented with an independent server or a server cluster composed of multiple servers. The present invention is described in detail below through specific embodiments.

[0032] like Figure 2 FIG. 1 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 to 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, 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:

[0035] Creating a local cache in the local process of the application service, and using the local cache as the 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 for the application service, used only for data caching and reading by the application service, such as the Caffeine local cache. The second-level cache is a public cache on the server where the application service resides, used for data caching and reading by all application services on that server, such as the Redis distributed cache. Financial systems often contain a large amount of private data that must be kept confidential, such as bank account passwords. When storing private data, financial application services typically choose to store it in a local cache used only by the application service itself, rather than in a public cache available to other application services on the same server, to prevent 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, initiate a first-level cache demotion operation to 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 cache hit times to local cache query times, the cache hit times are the number of times the requested data is successfully obtained from the local cache based on the request, and the local cache query times are 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 the Apollo configuration center, which is an open source distributed configuration center primarily used for unified management of configuration information in a microservice architecture. The basic steps for 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 statistics record in the log of the application service is obtained through the statistics 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 starts recording the cache statistical information 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 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 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 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 be cached in the second-level cache.

[0049] In another embodiment, when the preset cache tool is the Guava cache tool, cache statistics records for the application service are obtained through a Cache Stats object. The Cache Stats object provides access to statistical information such as cache hit rate, number of cache items loaded, and number of cache item evictions, and can be obtained through the Cache.stats() method. The hitCount attribute is the number of cache hits, which indicates the number of successful data retrievals from the cache.

[0050] The cache hit rate refers to the ratio of successful data retrievals from the cache to the total number of requests. Simply put, if a data request finds the required data in the cache, the request is considered a "hit," otherwise it's a "miss." The cache hit rate is an important metric for measuring cache effectiveness and is typically 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 initiating the downgrade operation of the first-level cache, the method further includes:

[0056] Detecting available cache space and a first-level cache hit rate 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, the request data that needs to be cached subsequently in the application is cached back into the first-level cache.

[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 based on 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 memory space waste in the local cache.

[0059] Cache downgrade refers to the process of discarding unimportant cached data based on a specific strategy to ensure normal system operation when system resources are limited or cache space is insufficient. Common causes of cache downgrade include insufficient system resources and cache space being full. Cache downgrade can prevent cache failure or performance degradation caused by cache space being full. In this embodiment, cache downgrade in a multi-level cache involves caching requested data in a public second-level cache when local first-level cache space is insufficient.

[0060] Cache degradation can be achieved in the following ways:

[0061] 1. Degradation based on access frequency: Degrade based on the access frequency of the data; 2. Degradation based on storage duration: Degrade based on the storage duration of the data in the cache; 3. Degradation based on data importance: Degrade based on the importance of the data.

[0062] In this embodiment, cache downgrade is performed based on 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 based on the number of times cache data is successfully obtained from the cache, and cache downgrade is performed based on 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 conditions, and if the cache entry eviction event meets the preset conditions, start the demotion 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 removing data from the cache to make room for new entries when the cache capacity reaches its limit. It is sometimes triggered by cache invalidation, which means that data that is no longer considered valid or fresh is removed from the cache. Cache entry eviction events are records of data being removed from the cache, obtained from the cache log file using a preset cache tool. The following eviction strategies are commonly used in caches: 1. Cache eviction occurs when the memory limit is reached and the client attempts to execute a command that may result in increased memory usage. 2. Delete cached data that has been used less recently to make room for newly added data. 3. Delete cached data with an expiration date that has expired to make room for newly added data. 4. Randomly delete cached data to make room for newly added data. 5. Randomly delete cached data with an expiration date 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, "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 determined 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 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 that indicates 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 or soft references to cached 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 cleaning 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] Obtain a security user identifier and a security cache key through the whitelist setting interface of the 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 from 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 whitelist are configured and updated through the distributed configuration center of the application service. The whitelist is configured through the whitelist settings interface of the distributed configuration center of the application service, and the blacklist is updated in real time by monitoring abnormal events in the log of the application service, such as the cache key of a 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 designated local storage, and the blacklist includes abnormal user identifiers and cache keys updated during the operation of the application service.

[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 the 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 the user identification of the client and matching it with the 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. 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 for cache downgrade include: 1. Setting up an early warning mechanism: Setting up graded warnings based on logs, and downgrading the cache service when a certain warning is reached; 2. Combining automatic and manual downgrades: The system can automatically downgrade based on some key data, and switches can also be configured to implement manual downgrade; 3. Emergency handling of serious errors: For serious errors, urgent manual downgrade is required, and an email warning of serious errors is sent.

[0088] In this embodiment, the cache of the request data is adjusted by comparing the cache hit rate with the 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 event of the first-level cache is monitored to confirm whether to downgrade the cache. The downgrade is automatically performed according to the event type of the monitored event. The cache of the specified request data is configured through the black and white lists. The cache of the request data itself is configured.

[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, preventing the private data from being mistakenly stored in the public cache due to cache degradation, which may lead to the leakage of application service data. 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 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 event 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 the black and white lists, it can ensure that the private 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 3FIG2 is a schematic diagram of a first embodiment of a server according to the present invention. Server 1 is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. Server 1 can be a single network server, a server group consisting of multiple network servers, or a cloud-based computing system consisting of a large number of hosts or network servers. Cloud computing is a type of distributed computing, consisting of a group of loosely coupled computers forming a super virtual computer.

[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 via a system bus. The memory 11 stores a cache adjustment program 10, which 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 the server 1 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 can be volatile or non-volatile. Specifically, the readable storage medium can be a storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an 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 magnetic disk, an optical disk, etc. In some embodiments, the readable storage medium can be an internal storage unit of the server 1, such as the hard disk of the server 1; in other embodiments, the storage medium can 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 (SMC), a secure digital (SD) card, a 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 the operating system and various application software installed on the server 1, such as storing the code of the cache adjustment program 10 in one 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] In some embodiments, the processor 12 can be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and a combination of various control chips. The processor 12 is the control core (Control Unit) of the electronic device, connecting each component of the entire electronic device using various interfaces and lines, and executing or executing programs or modules stored in the memory 11 (such as executing resource dynamic scheduling programs, etc.), as well as calling data stored in the memory 11, to perform 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 performing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run program codes stored in the memory 11 or process data, such as running the cache adjustment program 10.

[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 a server according to the present invention. The server 1 may further include a user interface 14, which may include a display and an input unit such as a keyboard. Optionally, the user interface 14 may also include a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an organic light-emitting diode (OLED) touch device. 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 a first-level cache hit rate of request data of the application service through cache statistical information records; when the first-level cache hit rate is less than a first threshold, generating a first-level cache warning notification for the application service and sending it to a server backend corresponding to the application service; and when the first-level cache hit rate is less than a second threshold, initiating a first-level cache demotion operation to cache the request data to be cached into the second-level cache, wherein the first threshold is greater than the second threshold;

[0100] S3. Monitor cache entry eviction events of the first-level cache, determine whether the cache entry eviction events meet preset conditions, and if so, initiate a downgrade operation of the first-level cache to cache the requested data to 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 steps S1-S4 of the first embodiment of the cache adjustment method of the present invention, and are not 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 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, which are used to describe the execution process of the cache adjustment program 10 in the server 1.

[0104] like Figure 5 FIG. 1 is a schematic diagram of the structure of a cache adjustment device provided by an 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 a second-level cache in the server where the application service is located;

[0107] The hit rate determination module 120 is configured to obtain a first-level cache hit rate of request data of the application service through cache statistical information records, generate a first-level cache warning notification for the application service and send it to a server backend corresponding to the application service when the first-level cache hit rate is less than a first threshold, and initiate a first-level cache demotion operation to cache the request data to be cached into a second-level cache when the first-level cache hit rate is less than a second threshold, wherein the first threshold is greater than the second threshold;

[0108] The eviction event determination module 130 is configured to monitor cache entry eviction events of the first-level cache, determine whether the cache entry eviction event satisfies a preset condition, and if so, initiate a downgrade operation of the first-level cache to cache the requested data to the second-level cache;

[0109] The blacklist and whitelist 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 whitelist and blacklist respectively, and 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, 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 the local process of the application service, and using the local cache as the 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 statistics record in the log of the application service is obtained through the statistics 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 first-level cache hit rate 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, the request data that needs to be cached subsequently in the application is cached back into the first-level cache.

[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 configured to:

[0126] Obtain a security user identifier and a security cache key through the whitelist setting interface of the 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 from 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 configured to:

[0131] When receiving a request from a client to access the application service, obtaining the user identification of the client and matching it with the 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. 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 and will not be repeated here. Each module in the above-mentioned cache adjustment device can be implemented in whole or in part through software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the corresponding operations of each of the above modules.

[0136] In addition, embodiments of the present invention further provide a computer-readable storage medium. The computer-readable storage medium can be either 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 disc read-only memory (CD-ROM), a USB memory, and the like. 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 roughly the same as the specific software implementation in the above-mentioned server 1, and will not be repeated here.

[0138] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0139] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, apparatus, article, or method comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, apparatus, article, or method. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, apparatus, article, or method comprising the element.

[0140] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, or of course by hardware, but in many cases the former is a better embodiment. Based on this 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. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling 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 scope of the patent of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the scope of patent protection of the present invention. It should be noted that if software tools or components other than those of our company appear in the embodiments of this application, they are only for illustration 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 request data of the application service through cache statistical information records; 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 a server backend corresponding to the application service; and when the first-level cache hit rate is less than a second threshold, initiating a first-level cache demotion operation to cache the request data that needs to be cached into a second-level cache, wherein the first threshold is greater than the second threshold; monitoring a cache entry eviction event of the first-level cache, determining whether the cache entry eviction event satisfies a preset condition, and if so, initiating a downgrade operation of the first-level cache to cache the requested data 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 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, wherein: 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 the local process of the application service, and using the local cache as the 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, wherein: The obtaining of the first-level cache hit rate of the request data of the application service by recording cache statistical information includes: When the application service is started, the cache statistics record in the log of the application service is obtained through the statistics 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, wherein: 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, wherein: The monitoring of the cache entry eviction event of the first-level cache and determining whether the cache entry eviction event meets 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, wherein: 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 the 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, wherein: The cache adjustment method further includes: Obtain a security user identifier and a security cache key through the whitelist setting interface of the 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 from 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 includes: A cache creation module, configured to create a first-level cache in the application service and a second-level cache in the server where the application service is located; a hit rate determination module, configured to obtain a first-level cache hit rate of 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 a server backend corresponding to the application service; and when the first-level cache hit rate is less than a second threshold, initiate a first-level cache demotion operation to cache the request data to be cached into the second-level cache, wherein the first threshold is greater than the second threshold; an eviction event judgment module, configured to monitor cache entry eviction events of the first-level cache, judge whether the cache entry eviction events meet preset conditions, and if so, initiate a downgrade operation of the first-level cache to cache the requested data to the second-level cache; The blacklist and whitelist 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 whitelist and blacklist respectively, and 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, 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 includes: 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.