Method and device for updating cache
Update cache data through section technology and reflection mechanism, the problems of high coupling, poor code reuse and resource waste in the existing technology are solved, and efficient cache update and code reuse are achieved.
Patent Information
- Application Number
- CN201810843150.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-07-27
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2038-07-27
AI Technical Summary
In the prior art, there are problems such as high coupling, poor code reusability, difficult to grasp the expiration time, and waste of resources caused by unreasonable access to the underlying storage medium.
The update task in the cache queue is determined through sectional technology, and the reflection mechanism and update parameters are used to update the data to be updated into the cache.
Improves the efficiency of updating cached data, increases code reuse, reduces coupling, and avoids waste of resources to access the underlying storage media without reason.
Smart Images

Figure CN110764796B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for updating cache. Background Art
[0002] In order to cope with high concurrent requests and fast response to requests, cache is usually used. Data may change, and data consistency needs to be considered. There are three main ways to ensure data consistency:
[0003] 1. Use the expiration mechanism to automatically replace and clean up invalid data;
[0004] 2. Cascade update: update the cache in time when updating the data to be updated;
[0005] 3. Long polling update: Use a timer to continuously obtain the latest data and update the cache.
[0006] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0007] 1. The expiration time is difficult to grasp. When the cache expiration time is set too long, it is easy to cause the accessed data to be expired; when the cache time is too short, the data will be imported into the underlying storage medium.
[0008] 2. It is necessary to write cache update code in the previous business logic, which results in high coupling and poor code reusability.
[0009] 3. It causes a waste of invalid resources. When there is no data update, the underlying storage medium may be accessed and the update operation may be performed for no reason. Summary of the invention
[0010] In view of this, an embodiment of the present invention provides a method and device for updating cache, which can overcome the technical problems of the prior art that the code for updating the cache needs to be written, resulting in too high coupling, poor code reusability, difficulty in grasping the expiration time, and waste of invalid resources caused by accessing the underlying storage medium and performing update operations for no reason when there is no data update, thereby achieving the technical effects of updating cache data, increasing code reusability, and improving update accuracy.
[0011] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for updating a cache is provided, comprising:
[0012] Use aspects to determine update tasks in the cache queue;
[0013] Determining update parameters corresponding to the update task;
[0014] The data to be updated corresponding to the update task is updated into the cache by using the reflection mechanism and the update parameters.
[0015] Optionally, the slices include: a slice for reading and a slice for updating;
[0016] The method of using a section to determine the update task in the cache queue includes:
[0017] Set component object annotations, logic method annotations, and list annotations;
[0018] According to the component object annotation and the logic method annotation, using the slice for reading to obtain the data to be updated corresponding to the real key; converting the format of the data to be updated into the set format;
[0019] According to the list annotation, the original key and the unique identifier of the data to be updated are stored in the custom class using the update facet; and the custom class is stored in the cache queue in a set format.
[0020] Optionally, the component object annotation marks the component object related to the cache operation;
[0021] The logic method annotation marks the business logic method in the component object that needs to update the cache; the logic method annotation includes: the original key corresponding to the component object, and the unique attribute of the business logic method corresponding to the data to be updated;
[0022] The list annotation includes a list of primitive keys in the logical method annotation.
[0023] Optionally, determining an update parameter corresponding to the update task includes:
[0024] Set up the cache definition dictionary locally and the cache data dictionary in the database;
[0025] An update parameter corresponding to the update task is determined according to the cache definition dictionary and the cache data dictionary.
[0026] Optionally, the locally setting the cache definition dictionary includes:
[0027] Determine the component object of the data to be updated according to the component object annotation;
[0028] Determine the business logic methods in the component objects that are annotated with logic method annotations;
[0029] The original key of the business logic method, the class type of the component object and the definition of the business logic method are stored in a local cache definition dictionary.
[0030] Optionally, setting a cache data dictionary in a database includes:
[0031] Obtain the real key corresponding to the business logic method;
[0032] The real key and the parameters in the business logic method are stored in a cache data dictionary of the database;
[0033] The real key is determined by the original key and the business logic method corresponding to the original key.
[0034] Optionally, the updating into the cache is done by multi-threaded asynchronous updating.
[0035] According to another aspect of an embodiment of the present invention, there is provided a device for updating a cache, comprising:
[0036] An update task determination module is used to determine the update tasks in the cache queue using aspects;
[0037] An update data determination module, used to determine update parameters corresponding to the update task;
[0038] The cache update module is used to update the to-be-updated data corresponding to the update task into the cache by using the reflection mechanism and the update parameters.
[0039] Optionally, the slices include: a slice for reading and a slice for updating;
[0040] The method of using a section to determine the update task in the cache queue includes:
[0041] Set component object annotations, logic method annotations, and list annotations;
[0042] According to the component object annotation and the logic method annotation, using the slice for reading to obtain the data to be updated corresponding to the real key; converting the format of the data to be updated into the set format;
[0043] According to the list annotation, the original key and the unique identifier of the data to be updated are stored in the custom class using the update facet; and the custom class is stored in the cache queue in a set format.
[0044] Optionally, the component object annotation marks the component object related to the cache operation;
[0045] The logic method annotation marks the business logic method in the component object that needs to update the cache; the logic method annotation includes: the original key corresponding to the component object, and the unique attribute of the business logic method corresponding to the data to be updated;
[0046] The list annotation includes a list of primitive keys in the logical method annotation.
[0047] Optionally, determining an update parameter corresponding to the update task includes:
[0048] Set up the cache definition dictionary locally and the cache data dictionary in the database;
[0049] An update parameter corresponding to the update task is determined according to the cache definition dictionary and the cache data dictionary.
[0050] Optionally, the locally setting the cache definition dictionary includes:
[0051] Determine the component object of the data to be updated according to the component object annotation;
[0052] Determine the business logic methods in the component objects that are annotated with logic method annotations;
[0053] The original key of the business logic method, the class type of the component object and the definition of the business logic method are stored in a local cache definition dictionary.
[0054] Optionally, setting a cache data dictionary in a database includes:
[0055] Obtain the real key corresponding to the business logic method;
[0056] The real key and the parameters in the business logic method are stored in a cache data dictionary of the database;
[0057] The real key is determined by the original key and the business logic method corresponding to the original key.
[0058] Optionally, the updating into the cache is done by multi-threaded asynchronous updating.
[0059] According to another aspect of an embodiment of the present invention, there is provided an electronic device for updating a cache, comprising:
[0060] one or more processors;
[0061] a storage device for storing one or more programs,
[0062] When the one or more programs are executed by the one or more processors, the one or more processors implement the method for updating cache of the present invention.
[0063] According to another aspect of an embodiment of the present invention, a computer readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for updating cache of the present invention is implemented.
[0064] One embodiment of the above invention has the following advantages or beneficial effects:
[0065] The present invention overcomes the technical problems of high coupling and poor code reusability caused by the need to write cache update code in the prior art by adopting the technical means of determining update tasks by aspects, thereby achieving the technical effect of efficiently updating cache data and increasing code reusability.
[0066] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0068] Figure 1 is a schematic diagram of the main process of a method for updating cache according to an embodiment of the present invention;
[0069] Figure 2 It is a schematic diagram of the main flow of steps for reading slice encapsulation in a specific embodiment of the method for updating cache according to an embodiment of the present invention;
[0070] Figure 3 It is a schematic diagram of the main flow of steps for updating slice encapsulation in a specific embodiment of the method for updating cache according to an embodiment of the present invention;
[0071] Figure 4 is a schematic diagram of a cache definition dictionary in a specific embodiment of a method for updating a cache according to an embodiment of the present invention;
[0072] Figure 5 is a schematic diagram of a cache data dictionary in a specific embodiment of a method for updating cache according to an embodiment of the present invention;
[0073] Figure 6 is a schematic diagram of main modules of a device for updating cache according to an embodiment of the present invention;
[0074] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0075] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0076] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0077] Figure 1 is a schematic diagram of the main process of the method for updating cache according to an embodiment of the present invention, such as Figure 1 As shown, including:
[0078] Step S101, using the slice to determine the update task in the cache queue;
[0079] Step S102, determining the update parameters corresponding to the update task;
[0080] Step S103: using the reflection mechanism and the update parameters, update the to-be-updated data corresponding to the update task into the cache.
[0081] The technical solution of the present invention aims to solve the technical problems in the prior art of difficult time control, poor reusability, and unnecessary access to the underlying storage medium when updating the cache, resulting in waste of resources.
[0082] The aspect refers to: using aspect-oriented programming (AOP) technology, it is possible to assist in determining the update task of updating the cache. By setting the technical means of the aspect, it is possible to process a step or a stage of business processing, thereby achieving the technical effect of reducing the coupling in the program. Optionally, an annotation entry point is defined in the method, thereby achieving the technical effect of facilitating the determination of cache data that needs to be updated and increasing code reuse. The cache data to be updated is determined according to the aspect, avoiding the technical defects of the existing technology that requires writing cache update code in the business logic before the update, resulting in too high coupling and poor code reusability.
[0083] Since the present invention adopts the technical means of updating the update task, it avoids the technical defect that the expiration time is difficult to grasp in the prior art due to the expiration mechanism. Since it adopts the accurate update according to the update task as needed, it avoids the technical defect that the cache expiration time is set too long, which easily causes the accessed data to be expired, and the cache time is too short, which will import the data into the underlying storage medium.
[0084] Optionally, before updating the to-be-updated data corresponding to the update task into the cache, the method further includes:
[0085] The original cache corresponding to the task is determined according to the key of the task, and then the expired cache corresponding to the update task in the cache is deleted.
[0086] Optionally, the slices include: a slice for reading and a slice for updating.
[0087] The aspect for reading and the aspect for updating only correspond to the steps of reading business or updating business, and there is no need to write code every time the annotation is intercepted, thereby achieving the technical effect of reducing coupling and improving code reuse.
[0088] Optionally, the step of encapsulating in the slice for reading includes:
[0089] Use the real key to read the data to be updated;
[0090] The format of the data to be updated is converted into a set format.
[0091] Figure 2 FIG. 1 is a schematic diagram of the main flow of steps for reading a slice in a specific embodiment of a method for updating a cache according to an embodiment of the present invention. Figure 2 As shown, since the data to be updated is stored in the database using the real key, the data to be updated can be read using the real key.
[0092] Hitting the cache means that the cache is queried based on the real key to see if there is a value associated with the real key in the database. If there is, it means that the cache is hit. If there is no value associated with the real key, the cache data related to the real key is loaded. Since the format of the data to be updated is a string in JSON (JavaScript Object Notation, JS object tag) format, the type of the data to be updated can be converted into the type of the real cache data.
[0093] Optionally, the real key and the JSON format string of the data to be updated are stored in a cache data dictionary of a Redis Hash structure whose original key and scope (unique identifier of the data to be updated) are domains in the CacheEnable annotation.
[0094] Optionally, the real key is determined by the original key and the parameters of the business logic method corresponding to the original key. The original key is dynamically obtained from the annotation by an EL (Expression Language) expression. The real key is executed by an API (Application Programming Interface) method that executes EL expressions in the Spring framework.
[0095] Optionally, the step of encapsulating in the updated slice includes:
[0096] Store the original key (original key) and the unique identifier of the data to be updated in a custom class (POJO class);
[0097] The custom class is stored in a cache queue (LIST) in a set format.
[0098] Figure 3 FIG. 1 is a schematic diagram of the main flow of the steps for updating the slice encapsulation in a specific embodiment of the method for updating the cache according to an embodiment of the present invention. Figure 3 As shown, using the update aspect, when the data corresponding to the original key changes, a cache update task is generated, and the task is placed in the cache queue in the database, thereby facilitating the subsequent cache update operation after obtaining the task from the cache queue.
[0099] Storing the original key and the unique identifier of the data to be updated in a custom class (POJO class) can achieve the technical effect of facilitating subsequent calls.
[0100] Optionally, determining the update data corresponding to the update task includes: determining the update data corresponding to the update task in a dictionary;
[0101] Setting the dictionary includes: setting a cache definition dictionary locally and setting a cache data dictionary in a database.
[0102] The dictionary in the present invention refers to an instance object of the HashMap class. The HashMap is an implementation of the Map interface based on a hash table. The HashMap is a hash table, and the content stored in it is a key-value mapping; the value corresponding to the key can be determined according to the key. By setting the dictionary, the value corresponding to the key can be directly obtained according to the key of the dictionary, thereby achieving a technical effect of simple and convenient data update.
[0103] Optionally, the dictionary can be set locally, such as in a Java virtual machine (JVM), thereby achieving the technical effect of greatly improving the search speed; the dictionary can also be optionally set in a database, such as a redis database, thereby achieving the technical effect of sharing the data in the dictionary.
[0104] Specifically, according to the original key in the interception annotation of the aspect used for reading, the component object and the definition of the business logic method that the original key acts on can be obtained from the local dictionary; according to the original key in the aspect used for updating and the unique attribute of the data to be updated, the real cache key and the specific parameters of the method call can be obtained from the dictionary.
[0105] Among them, in the present invention, by obtaining the data in the dictionary, the reflection mechanism can be used to accurately set the latest cache data into the cache as needed, thereby avoiding the waste of invalid resources caused by the difficulty in grasping the expiration time and the possibility of accessing the underlying storage medium and performing update operations without reason when there is no data update.
[0106] Figure 4 is a schematic diagram of a cache definition dictionary in a specific embodiment of a method for updating a cache according to an embodiment of the present invention, such as Figure 4 As shown, optionally, the locally setting the cache definition dictionary includes:
[0107] Determine the component object to be updated in the cache according to the component object annotation;
[0108] Determine the business logic methods in the component objects that are annotated with logic method annotations;
[0109] The original key of the business logic method, the class type of the component object and the definition of the business logic method are stored in a local cache definition dictionary.
[0110] Since the reflection mechanism is used when updating the cache, storing the class type corresponding to the original key in the local cache definition dictionary can assist in obtaining the specific data to be updated. The definition of the business logic method includes but is not limited to: the name of the business logic method definition, the type of the business logic method parameter, the return value type, and the method access attributes.
[0111] Figure 5 is a schematic diagram of a cache data dictionary in a specific embodiment of a method for updating cache according to an embodiment of the present invention, such as Figure 5 As shown, optionally, setting a cache data dictionary in a database includes:
[0112] Get the real key of the business logic method;
[0113] The real key and the parameters in the business logic method are stored in a cache data dictionary of the database.
[0114] Considering that the real key and the parameters in the business logic method need to be shared by multiple instances, the real key and the parameters in the business logic method can be stored in a cache data dictionary of the database.
[0115] The parameters in the business logic method are stored in the form of a JSON format string; the data structure is a hash structure of the original key and the corresponding unique identifier of the data object to be updated.
[0116] Optionally, the storage formats of the cache definition dictionary and the cache data dictionary are both hash formats.
[0117] Optionally, before using the aspect to determine the update task in the cache queue, it also includes: custom annotations;
[0118] The annotations include: component object annotations (CacheBean annotations), logic method annotations (CacheEnable annotations), and list annotations (CacheNotify annotations);
[0119] The component object annotation marks the component object related to the cache operation for quick positioning in the component object. Optionally, a third-party framework is used to manage the life cycle of the objects in the class, such as the spring framework.
[0120] The logic method annotation marks the business logic method in the component object that needs to update the cache; the logic method annotation includes: the original key corresponding to the component object, and the unique attribute of the business logic method corresponding to the data to be updated; wherein, the CacheEnable annotation is used to mark the business logic method that needs to enable the cache; the CacheEnable annotation can also include the expiration time of the cache, and its default value is 10 minutes; the unique attributes of the data to be updated include: for example, the merchant ID of the merchant and the user's account number.
[0121] The list annotation includes a list of primitive keys in the logical method annotation.
[0122] Optionally, the component object corresponding to the cache to be updated can be determined according to the CacheBean annotation, and then the data stored in the cache definition dictionary can be determined according to the logic method corresponding to the CacheEnable annotation.
[0123] Optionally, the component object corresponding to the cache to be updated can be determined according to the CacheBean annotation, and then the data stored in the cache definition dictionary can be determined according to the logic method corresponding to the CacheEnable annotation.
[0124] Optionally, using multi-threaded asynchronous updates can improve the efficiency of updating the cache and achieve the technical effect of not blocking the original update operation.
[0125] Figure 6 is a schematic diagram of main modules of a device for updating cache according to an embodiment of the present invention,
[0126] like Figure 6 As shown, according to another aspect of an embodiment of the present invention, a device 600 for updating a cache is provided, comprising:
[0127] Module 601, an update task determination module, is used to determine the update tasks in the cache queue using the slice;
[0128] Module 602, an update data determination module, is used to determine the update parameters corresponding to the update task;
[0129] Module 603, a cache update module, is used to update the to-be-updated data corresponding to the update task into the cache by using a reflection mechanism and the update parameters.
[0130] Optionally, the slices include: a slice for reading and a slice for updating;
[0131] The method of using a section to determine the update task in the cache queue includes:
[0132] Set component object annotations, logic method annotations, and list annotations;
[0133] According to the component object annotation and the logic method annotation, using the slice for reading to obtain the data to be updated corresponding to the real key; converting the format of the data to be updated into the set format;
[0134] According to the list annotation, the original key and the unique identifier of the data to be updated are stored in the custom class using the update facet; and the custom class is stored in the cache queue in a set format.
[0135] Optionally, the component object annotation marks the component object related to the cache operation;
[0136] The logic method annotation marks the business logic method in the component object that needs to update the cache; the logic method annotation includes: the original key corresponding to the component object, and the unique attribute of the business logic method corresponding to the data to be updated;
[0137] The list annotation includes a list of primitive keys in the logical method annotation.
[0138] Optionally, determining an update parameter corresponding to the update task includes:
[0139] Set up the cache definition dictionary locally and the cache data dictionary in the database;
[0140] An update parameter corresponding to the update task is determined according to the cache definition dictionary and the cache data dictionary.
[0141] Optionally, the locally setting the cache definition dictionary includes:
[0142] Determine the component object of the data to be updated according to the component object annotation;
[0143] Determine the business logic methods in the component objects that are annotated with logic method annotations;
[0144] The original key of the business logic method, the class type of the component object and the definition of the business logic method are stored in a local cache definition dictionary.
[0145] Optionally, setting a cache data dictionary in a database includes:
[0146] Obtain the real key corresponding to the business logic method;
[0147] The real key and the parameters in the business logic method are stored in a cache data dictionary of the database;
[0148] The real key is determined by the original key and the business logic method corresponding to the original key.
[0149] Optionally, the updating into the cache is done by multi-threaded asynchronous updating.
[0150] Figure 7 An exemplary system architecture 700 is shown to which the update cache method or update cache device according to the embodiment of the present invention can be applied.
[0151] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0152] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0153] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0154] The server 705 may be a server that provides various services, such as a backend management server (only for example) that supports shopping websites browsed by users using the terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only for example) to the terminal device.
[0155] It should be noted that the update cache method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the update cache device is generally set in the server 705 .
[0156] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0157] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0158] like Figure 8 As shown, the computer system 800 includes a central processing module (CPU) 801, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 802 or the program loaded from the storage part 808 to the random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0159] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.
[0160] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing module (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.
[0161] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0162] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0163] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a sending module, an acquisition module, a determination module, and a first processing module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the sending module may also be described as a "module for sending a picture acquisition request to the connected server."
[0164] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0165] Use aspects to determine update tasks in the cache queue;
[0166] Determining update parameters corresponding to the update task;
[0167] The data to be updated corresponding to the update task is updated into the cache by using the reflection mechanism and the update parameters.
[0168] According to the technical solution of the embodiment of the present invention, the following beneficial effects can be achieved:
[0169] The present invention overcomes the technical problems of high coupling and poor code reusability caused by the need to write cache update code in the prior art by adopting the technical means of determining update tasks by aspects, thereby achieving the technical effect of improving the efficiency of updating cache data and increasing code reusability.
[0170] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for updating a cache, characterized in that: include: Determine the update task in the cache queue by using the slice; wherein the slice includes: a slice for reading and a slice for updating; the process includes: Set component object annotations, logic method annotations, and list annotations; wherein the component object annotations mark component objects related to cache operations; the logic method annotations mark business logic methods in component objects that need to update cache, including: the original key corresponding to the component object; the list annotations include a list of original keys in the logic method annotations; According to the component object annotation and the logic method annotation, using the read aspect to obtain the data to be updated corresponding to the real key; According to the list annotation, the original key and the unique identifier of the data to be updated are stored in the custom class using the update facet; the custom class is stored in the cache queue in a set format; Determining update parameters corresponding to the update task includes: setting a cache definition dictionary locally and setting a cache data dictionary in a database; determining update parameters corresponding to the update task according to the cache definition dictionary and the cache data dictionary; wherein, setting the cache definition dictionary locally includes: determining a component object of data to be updated according to a component object annotation; determining a business logic method annotated with a logic method annotation in the component object; storing the original key of the business logic method, the class type of the component object, and the definition of the business logic method in the local cache definition dictionary; The data to be updated corresponding to the update task is updated into the cache by using the reflection mechanism and the update parameters.
2. The method according to claim 1, characterized in that The format of the data to be updated is converted into a set format.
3. The method according to claim 2, characterized in that The logic method annotation includes: the business logic method corresponds to the unique attribute of the data to be updated.
4. The method according to claim 1, characterized in that: The cache data dictionary is set in the database, including: Obtain the real key corresponding to the business logic method; The real key and the parameters in the business logic method are stored in a cache data dictionary of the database; The real key is determined by the original key and the business logic method corresponding to the original key.
5. The method according to claim 1, characterized in that The updating method to the cache is multi-threaded asynchronous updating.
6. A device for updating a cache, characterized in that: include: An update task determination module is used to determine the update task in the cache queue by using a slice; wherein the slice includes: a slice for reading and a slice for updating; the process includes: Set component object annotations, logic method annotations, and list annotations; wherein the component object annotations mark component objects related to cache operations; the logic method annotations mark business logic methods in component objects that need to update cache, including: the original key corresponding to the component object; the list annotations include a list of original keys in the logic method annotations; According to the component object annotation and the logic method annotation, using the read aspect to obtain the data to be updated corresponding to the real key; According to the list annotation, the original key and the unique identifier of the data to be updated are stored in the custom class using the update facet; the custom class is stored in the cache queue in a set format; An update data determination module is used to determine the update parameters corresponding to the update task, including: setting a cache definition dictionary locally and setting a cache data dictionary in a database; determining the update parameters corresponding to the update task according to the cache definition dictionary and the cache data dictionary; wherein, setting the cache definition dictionary locally includes: determining the component object of the data to be updated according to the component object annotation; determining the business logic method annotated with the logic method annotation in the component object; storing the original key of the business logic method, the class type of the component object and the definition of the business logic method in the local cache definition dictionary; The cache update module is used to update the to-be-updated data corresponding to the update task into the cache by using the reflection mechanism and the update parameters.
7. The device according to claim 6, characterized in that The format of the data to be updated is converted into a set format.
8. The device according to claim 7, characterized in that The logic method annotation includes: the business logic method corresponds to the unique attribute of the data to be updated.
9. The device according to claim 6, characterized in that The cache data dictionary is set in the database, including: Obtain the real key corresponding to the business logic method; The real key and the parameters in the business logic method are stored in a cache data dictionary of the database; The real key is determined by the original key and the business logic method corresponding to the original key.
10. The device according to claim 6, characterized in that The updating method to the cache is multi-threaded asynchronous updating.
11. An electronic device for updating a cache, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Annotation-based local cache realization method, storage device and electronic device
CN107463378A
Service-coupled intelligent cashing method
CN107704573A