CN110764796A - Method and device for updating cache - Google Patents

Method and device for updating cache Download PDF

Info

Publication number
CN110764796A
CN110764796A CN201810843150.7A CN201810843150A CN110764796A CN 110764796 A CN110764796 A CN 110764796A CN 201810843150 A CN201810843150 A CN 201810843150A CN 110764796 A CN110764796 A CN 110764796A
Authority
CN
China
Prior art keywords
cache
updating
data
annotation
component object
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810843150.7A
Other languages
Chinese (zh)
Inventor
刘小云
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810843150.7A priority Critical patent/CN110764796A/en
Publication of CN110764796A publication Critical patent/CN110764796A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Abstract

The invention discloses a method and a device for updating a cache, and relates to the technical field of computers. One embodiment of the method comprises: determining an updating task in a cache queue by using a tangent plane; determining an updating parameter corresponding to the updating task; and updating the data to be updated corresponding to the updating task into a cache by using a reflection mechanism and the updating parameters. The implementation mode overcomes the technical problems that the coupling is too high, the code reusability is poor, the expiration time is not easy to grasp, and the waste of invalid resources caused by accessing a bottom storage medium and executing the updating operation can be caused without accident when no data is updated in the prior art because codes for updating the cache need to be written, thereby achieving the technical effects of efficiently updating the cache and increasing the code reusability.

Description

Method and device for updating cache
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for updating a cache.
Background
In order to handle high concurrency requests and fast response of requests, caching is often used. The data may have variation and the problem of data consistency needs to be considered. The ways of ensuring the consistency of data are mainly three:
1. the expired data is automatically replaced and cleaned by an expiration mechanism;
2. and (3) cascading updating: updating the cache in time when the data to be updated is updated;
3. and (3) long polling updating: and adopting a timing program to continuously acquire the latest data and update the cache.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1. the expiration time is not easy to be grasped, and when the cache expiration time is set too long, the accessed data is easily expired; when the buffering time is too short, data can be imported into the underlying storage medium.
2. The codes for updating the cache are required to be written in the previous business logic, the coupling is too high, and the code reusability is poor.
3. Resulting in waste of invalid resources that may inadvertently access the underlying storage medium and perform an update operation when there is no data update.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for updating a cache, which can overcome the technical problems of too high coupling, poor code reusability, and hard to grasp expiration time caused by writing a code for updating the cache in the prior art, and waste of invalid resources caused by accessing a bottom storage medium and performing an update operation without any reason when no data is updated, thereby achieving the technical effects of updating the cache data, increasing code reusability, and improving update accuracy.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a method for updating a cache, including:
determining an updating task in a cache queue by using a tangent plane;
determining an updating parameter corresponding to the updating task;
and updating the data to be updated corresponding to the updating task into a cache by using a reflection mechanism and the updating parameters.
Optionally, the section comprises: a slice for reading and a slice for updating;
the determining of the update task in the cache queue by using the tangent plane includes:
setting component object annotation, logic method annotation and list annotation;
acquiring data to be updated corresponding to the real key by using a read tangent plane according to the component object annotation and the logic method annotation; converting the format of the data to be updated into a set format;
storing the original key and the unique identifier of the data to be updated into a custom class by using a section for updating according to the list annotation; and storing the self-defined class into a buffer queue in a set format.
Optionally, the component object annotation annotates a component object related to a cache operation;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated;
the list annotation includes a list of the original keys in the logical method annotation.
Optionally, determining an update parameter corresponding to the update task includes:
setting a cache definition dictionary locally and setting a cache data dictionary in a database;
and determining an updating parameter corresponding to the updating task according to the cache definition dictionary and the cache data dictionary.
Optionally, the locally setting a cache definition dictionary includes:
determining a component object of the data to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
Optionally, the setting a cache data dictionary in the database includes:
acquiring a real key corresponding to the business logic method;
storing the real key and the parameters in the business logic method in a cache data dictionary of a database;
the real key is determined by an original key and a business logic method corresponding to the original key.
Optionally, the updating into the cache is performed by multithreading asynchronous updating.
According to another aspect of the embodiments of the present invention, there is provided an apparatus for updating a cache, including:
the updating task determining module is used for determining the updating task in the cache queue by using the tangent plane;
the updating data determining module is used for determining the updating parameters corresponding to the updating tasks;
and the cache updating module is used for updating the data to be updated corresponding to the updating task into a cache by utilizing a reflection mechanism and the updating parameters.
Optionally, the section comprises: a slice for reading and a slice for updating;
the determining of the update task in the cache queue by using the tangent plane includes:
setting component object annotation, logic method annotation and list annotation;
acquiring data to be updated corresponding to the real key by using a read tangent plane according to the component object annotation and the logic method annotation; converting the format of the data to be updated into a set format;
storing the original key and the unique identifier of the data to be updated into a custom class by using a section for updating according to the list annotation; and storing the self-defined class into a buffer queue in a set format.
Optionally, the component object annotation annotates a component object related to a cache operation;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated;
the list annotation includes a list of the original keys in the logical method annotation.
Optionally, determining an update parameter corresponding to the update task includes:
setting a cache definition dictionary locally and setting a cache data dictionary in a database;
and determining an updating parameter corresponding to the updating task according to the cache definition dictionary and the cache data dictionary.
Optionally, the locally setting a cache definition dictionary includes:
determining a component object of the data to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
Optionally, the setting a cache data dictionary in the database includes:
acquiring a real key corresponding to the business logic method;
storing the real key and the parameters in the business logic method in a cache data dictionary of a database;
the real key is determined by an original key and a business logic method corresponding to the original key.
Optionally, the updating into the cache is performed by multithreading asynchronous updating.
According to another aspect of the embodiments of the present invention, there is provided an electronic device for updating a cache, including:
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 are caused to implement the method of updating a cache of the present invention.
According to another aspect of embodiments of the present invention, there is provided a computer readable medium having stored thereon a computer program which, when executed by a processor, implements a method of updating a cache according to the present invention.
One embodiment of the above invention has the following advantages or benefits:
the invention adopts the technical means of determining the updating task by the section, thereby overcoming the technical problems of too high coupling and poor code reusability caused by the need of writing and updating the cached codes in the prior art, and further achieving the technical effects of efficiently updating the cached data and increasing the code reusability.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of a method of updating a cache according to an embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating a main flow of a step of facet encapsulation for reading in an embodiment of a method for updating a cache according to the present invention;
FIG. 3 is a schematic diagram illustrating a main flow of steps for updating slice encapsulation in an embodiment of a method for updating a cache according to the present invention;
FIG. 4 is a diagram illustrating a cache definition dictionary in an embodiment of a method for updating a cache according to the present invention;
FIG. 5 is a diagram illustrating a cached data dictionary in an embodiment of a method for updating a cache according to the present invention;
FIG. 6 is a diagram illustrating major blocks of an apparatus for updating a cache according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 8 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a method for updating a cache according to an embodiment of the present invention, as shown in fig. 1, including:
step S101, determining an updating task in a cache queue by using a tangent plane;
s102, determining an updating parameter corresponding to the updating task;
and step S103, updating the data to be updated corresponding to the updating task into a cache by using a reflection mechanism and the updating parameters.
The technical scheme of the invention aims to: the method solves the technical problems that time is not easy to control, reusability is poor, and resources are wasted due to the fact that the underlying storage medium is accessed without reasons when the cache is updated in the prior art.
The section is as follows: the update task of determining the update cache can be assisted by using an Aspect Oriented Programming (AOP) technology. By means of the technical means of setting the section, the processing can be performed aiming at one section or one stage of business processing, and further the technical effect of reducing the coupling degree in the program is achieved. Optionally, an annotation entry point is defined in the method, so that the technical effects of conveniently determining cache data needing to be updated and increasing the code reusability are achieved. The cache data to be updated is determined according to the tangent plane, and the technical defects of high coupling and poor code reusability caused by the fact that the cache updating code needs to be written in the service logic before updating in the prior art are avoided.
The invention adopts the technical means of updating the updating task, thereby avoiding the technical defect that the expiration time is not easy to grasp because the expiration mechanism is adopted in the prior art. Due to the fact that accurate updating is carried out according to the requirements according to the updating task, the technical defect that data are imported into an underlying storage medium when the accessed data are expired and the cache time is too short due to too long cache expiration time is avoided.
Optionally, before updating the data to be updated corresponding to the update task into the cache, the method further includes:
and determining an original cache corresponding to the task according to the key of the task, and further deleting an expired cache corresponding to the updated task in the cache.
Optionally, the section comprises: a slice for reading and a slice for updating.
The section for reading and the section for updating only correspond to the step of reading the service or updating the service, and codes do not need to be written every time the annotation is intercepted, so that the technical effects of reducing the coupling degree and improving the code reusability are achieved.
Optionally, the step of packaging in the section for reading includes:
reading data to be updated by using a real key;
and converting the format of the data to be updated into a set format.
Fig. 2 is a schematic diagram illustrating a main flow of a step of updating a slice for reading in an embodiment of a method for updating a cache according to the present invention. As shown in fig. 2, 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.
The cache hit refers to that whether a value associated with the real key exists in a database is queried in the cache according to the real key, and if the value exists, the cache hit is indicated. And if the value associated with the real key does not exist, loading the cache data related to the real key. Since the format of the read data to be updated is a JSON (JSON object tagging) format character string, the type of the data to be updated can be converted into the type of the real cache data.
Optionally, the JSON format character strings of the real key and the data to be updated are stored in a cache data dictionary of a Hash structure of Redis in which an original key and a scope (unique identifier of the data to be updated) are domains in the CacheEnable annotation.
Optionally, the real key is determined by an original key and a parameter of a business logic method corresponding to the original key. Wherein the original key is dynamically obtained from annotations by an EL (expression language) expression. The real key is executed by an api (application Programming interface) method that executes an EL expression in a Spring framework.
Optionally, the step of encapsulating in the updated section includes:
storing an original key (original key) and a unique identifier of data to be updated into a self-defined class (POJO class);
storing the custom class in a set format in a buffer queue (LIST).
Fig. 3 is a schematic diagram of a main flow of steps for updating a slice encapsulation in an embodiment of a method for updating a cache according to the present invention. As shown in fig. 3, by using the section for updating, after the data corresponding to the original key is changed, a task for updating the cache is generated and is placed in a cache queue in the database, so that the subsequent operation of updating the cache after acquiring the task from the cache queue is facilitated.
The original key and the unique identifier of the data to be updated are stored in the self-defined class (POJO class), so that the technical effect of facilitating subsequent calling can be achieved.
Optionally, determining update data corresponding to the update task includes: determining updating data corresponding to the updating task in a dictionary;
setting the dictionary includes: setting a cache definition dictionary locally and setting a cache data dictionary in a database.
The dictionary refers to an instance object using the HashMap class in the present invention. The HashMap is realized by a Map interface based on a hash table. The HashMap is a hash table, and the stored content is key-value mapping (key-value); from the key, the value (value) corresponding to the key can be determined. The value corresponding to the key can be directly obtained according to the key of the dictionary by setting the dictionary, and the technical effect of simplicity and convenience in data updating is further achieved.
Optionally, the dictionary may be locally arranged, such as in a java virtual machine (jvm), so as to achieve the technical effect of greatly improving the search speed; optionally, the dictionary is also set in a database, such as a database redis, so as to achieve the technical effect of sharing data in the dictionary.
Specifically, the definition of a component object and a business logic method of the original key function can be obtained from a local dictionary according to the original key in the section interception annotation used for reading; and acquiring real cache keys and specific method call parameters from the dictionary according to the unique attributes of the original keys and the data to be updated in the section for updating.
According to the invention, by acquiring the data in the dictionary, the latest cache data can be accurately set in the cache as required by using a reflection mechanism, so that the waste of invalid resources caused by the fact that the expiration time is not easy to grasp, and the bottom-layer storage medium is visited without any reason and the updating operation is executed when the data is not updated is avoided.
Fig. 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, as shown in fig. 4, optionally, the locally setting the cache definition dictionary includes:
determining a component object to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
Since a reflection mechanism is adopted when the cache is updated, the class type corresponding to the original key stored in the local cache definition dictionary can assist in acquiring specific data to be updated. The definition of the business logic method includes but is not limited to: the name of the definition of the business logic method, the type of the parameter of the business logic method, the type of the return value and the access attribute of the method.
Fig. 5 is a schematic diagram of a cached data dictionary in a specific embodiment of a method for updating a cache according to an embodiment of the present invention, and as shown in fig. 5, optionally, the setting of the cached data dictionary in the database includes:
obtaining a real key of the business logic method;
and storing the parameters in the real key and the business logic method in a cache data dictionary of a database.
Considering that the real key and the parameter in the business logic method need to be shared by multiple instances, the real key and the parameter in the business logic method can be stored in a cache data dictionary of a database.
Wherein, the parameters in the business logic method are stored in the form of JSON format character strings; the data structure is a hash structure of the unique identifier of the original key and the corresponding data object to be updated.
Optionally, the storage formats of the cache definition dictionary and the cache data dictionary are both hash formats.
Optionally, before determining the update task in the buffer queue by using the tangent plane, the method further includes: self-defining annotations;
the annotation comprises: component object annotations (CacheBean annotations), logical method annotations (CacheEnable annotations), list annotations (CacheNotify annotations);
the component object annotation labels the component objects related to the cache operation, and is used for quickly positioning the component objects, and optionally, managing the life cycle of the objects in the class by using a third-party framework, such as a spring framework;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated; wherein, the cacheEnable annotation is used for marking the service logic method needing to start the cache; the cacheable annotation may also contain a cached expiration time with a default value of 10 minutes; the unique attributes of the data to be updated include: such as the merchant ID of the merchant, the account number of the user.
The list annotation includes a list of the original keys in the logical method annotation.
Optionally, a component object corresponding to the cache to be updated may be determined according to the CacheBean annotation, and then the data stored in the cache definition dictionary may be determined according to the logical method corresponding to the CacheEnable annotation.
Optionally, a component object corresponding to the cache to be updated may be determined according to the CacheBean annotation, and then the data stored in the cache definition dictionary may be determined according to the logical method corresponding to the CacheEnable annotation.
Optionally, the cache updating efficiency can be improved by using multi-thread asynchronous updating, and the technical effect of not blocking the original updating operation is achieved.
Figure 6 is a schematic diagram of the main blocks of an apparatus for updating a cache according to an embodiment of the present invention,
as shown in fig. 6, according to another aspect of the embodiment of the present invention, there is provided an apparatus 600 for updating a cache, including:
the module 601 and the update task determination module are used for determining the update task in the cache queue by using the tangent plane;
the module 602 and the update data determining module are configured to determine an update parameter corresponding to the update task;
the module 603 and the cache updating module are configured to update the data to be updated corresponding to the update task to the cache by using the reflection mechanism and the update parameter.
Optionally, the section comprises: a slice for reading and a slice for updating;
the determining of the update task in the cache queue by using the tangent plane includes:
setting component object annotation, logic method annotation and list annotation;
acquiring data to be updated corresponding to the real key by using a read tangent plane according to the component object annotation and the logic method annotation; converting the format of the data to be updated into a set format;
storing the original key and the unique identifier of the data to be updated into a custom class by using a section for updating according to the list annotation; and storing the self-defined class into a buffer queue in a set format.
Optionally, the component object annotation annotates a component object related to a cache operation;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated;
the list annotation includes a list of the original keys in the logical method annotation.
Optionally, determining an update parameter corresponding to the update task includes:
setting a cache definition dictionary locally and setting a cache data dictionary in a database;
and determining an updating parameter corresponding to the updating task according to the cache definition dictionary and the cache data dictionary.
Optionally, the locally setting a cache definition dictionary includes:
determining a component object of the data to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
Optionally, the setting a cache data dictionary in the database includes:
acquiring a real key corresponding to the business logic method;
storing the real key and the parameters in the business logic method in a cache data dictionary of a database;
the real key is determined by an original key and a business logic method corresponding to the original key.
Optionally, the updating into the cache is performed by multithreading asynchronous updating.
Fig. 7 illustrates an exemplary system architecture 700 to which the update caching method or the update caching apparatus of embodiments of the invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. The terminal devices 701, 702, 703 may have installed thereon various communication client applications, such as a shopping-like application, a web browser application, a search-like application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only).
The terminal devices 701, 702, 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 701, 702, 703. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the update caching method provided by the embodiment of the present invention is generally executed by the server 705, and accordingly, the update caching apparatus is generally disposed in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a central processing module (CPU)801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. 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 necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program performs the above-described functions defined in the system of the present invention when executed by the central processing module (CPU) 801.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not form a limitation on the modules themselves in some cases, and for example, the sending module may also be described as a "module sending a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
determining an updating task in a cache queue by using a tangent plane;
determining an updating parameter corresponding to the updating task;
and updating the data to be updated corresponding to the updating task into a cache by using a reflection mechanism and the updating parameters.
According to the technical scheme of the embodiment of the invention, the following beneficial effects can be achieved:
the invention adopts the technical means of determining the updating task by the tangent plane, thereby overcoming the technical problems of too high coupling and poor code reusability caused by the need of writing and updating the cached codes in the prior art, and further achieving the technical effects of improving the efficiency of updating the cached data and increasing the code reusability.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A method for updating a cache, comprising:
determining an updating task in a cache queue by using a tangent plane;
determining an updating parameter corresponding to the updating task;
and updating the data to be updated corresponding to the updating task into a cache by using a reflection mechanism and the updating parameters.
2. The method of claim 1, wherein the cutting plane comprises: a slice for reading and a slice for updating;
the determining of the update task in the cache queue by using the tangent plane includes:
setting component object annotation, logic method annotation and list annotation;
acquiring data to be updated corresponding to the real key by using a read tangent plane according to the component object annotation and the logic method annotation; converting the format of the data to be updated into a set format;
storing the original key and the unique identifier of the data to be updated into a custom class by using a section for updating according to the list annotation; and storing the self-defined class into a buffer queue in a set format.
3. The method of claim 2, wherein the component object annotation tags a component object related to a cache operation;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated;
the list annotation includes a list of the original keys in the logical method annotation.
4. The method of claim 3, wherein determining the update parameters corresponding to the update task comprises:
setting a cache definition dictionary locally and setting a cache data dictionary in a database;
and determining an updating parameter corresponding to the updating task according to the cache definition dictionary and the cache data dictionary.
5. The method of claim 4, wherein locally setting the cache definition dictionary comprises:
determining a component object of the data to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
6. The method of claim 5, wherein the setting of the cached data dictionary in the database comprises:
acquiring a real key corresponding to the business logic method;
storing the real key and the parameters in the business logic method in a cache data dictionary of a database;
the real key is determined by an original key and a business logic method corresponding to the original key.
7. The method of claim 1, wherein the update into the cache is a multithreaded asynchronous update.
8. An apparatus for updating a cache, comprising:
the updating task determining module is used for determining the updating task in the cache queue by using the tangent plane;
the updating data determining module is used for determining the updating parameters corresponding to the updating tasks;
and the cache updating module is used for updating the data to be updated corresponding to the updating task into a cache by utilizing a reflection mechanism and the updating parameters.
9. The apparatus of claim 8, wherein the cut surface comprises: a slice for reading and a slice for updating;
the determining of the update task in the cache queue by using the tangent plane includes:
setting component object annotation, logic method annotation and list annotation;
acquiring data to be updated corresponding to the real key by using a read tangent plane according to the component object annotation and the logic method annotation; converting the format of the data to be updated into a set format;
storing the original key and the unique identifier of the data to be updated into a custom class by using a section for updating according to the list annotation; and storing the self-defined class into a buffer queue in a set format.
10. The apparatus of claim 9, wherein the component object annotation tags a component object related to a cache operation;
annotating the service logic method needing to update the cache in the component object by the logic method; the logical method notes include: the original key corresponding to the component object and the service logic method correspond to the unique attribute of the data to be updated;
the list annotation includes a list of the original keys in the logical method annotation.
11. The apparatus of claim 10, wherein determining the update parameters corresponding to the update task comprises:
setting a cache definition dictionary locally and setting a cache data dictionary in a database;
and determining an updating parameter corresponding to the updating task according to the cache definition dictionary and the cache data dictionary.
12. The apparatus of claim 11, wherein the locally setting a cache definition dictionary comprises:
determining a component object of the data to be updated according to the component object annotation;
determining a business logic method marked 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 into a local cache definition dictionary.
13. The apparatus of claim 12, wherein the setting of the cached data dictionary in the database comprises:
acquiring a real key corresponding to the business logic method;
storing the real key and the parameters in the business logic method in a cache data dictionary of a database;
the real key is determined by an original key and a business logic method corresponding to the original key.
14. The apparatus of claim 7, wherein the means for updating into the cache is a multi-threaded asynchronous update.
15. An electronic device for updating a cache, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
16. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN201810843150.7A 2018-07-27 2018-07-27 Method and device for updating cache Pending CN110764796A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810843150.7A CN110764796A (en) 2018-07-27 2018-07-27 Method and device for updating cache

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810843150.7A CN110764796A (en) 2018-07-27 2018-07-27 Method and device for updating cache

Publications (1)

Publication Number Publication Date
CN110764796A true CN110764796A (en) 2020-02-07

Family

ID=69327746

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810843150.7A Pending CN110764796A (en) 2018-07-27 2018-07-27 Method and device for updating cache

Country Status (1)

Country Link
CN (1) CN110764796A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111797119A (en) * 2020-05-19 2020-10-20 武汉乐程软工科技有限公司 Caching device, caching system and caching method
CN113312391A (en) * 2021-06-01 2021-08-27 上海万物新生环保科技集团有限公司 Method and equipment for cache asynchronous delay refreshing
CN113486037A (en) * 2021-07-27 2021-10-08 北京京东乾石科技有限公司 Cache data updating method, manager and cache server
CN116166682A (en) * 2023-04-26 2023-05-26 国家工业信息安全发展研究中心 Data updating method and server

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111797119A (en) * 2020-05-19 2020-10-20 武汉乐程软工科技有限公司 Caching device, caching system and caching method
CN111797119B (en) * 2020-05-19 2024-01-30 武汉乐程软工科技有限公司 Caching device, system and caching method
CN113312391A (en) * 2021-06-01 2021-08-27 上海万物新生环保科技集团有限公司 Method and equipment for cache asynchronous delay refreshing
CN113486037A (en) * 2021-07-27 2021-10-08 北京京东乾石科技有限公司 Cache data updating method, manager and cache server
CN116166682A (en) * 2023-04-26 2023-05-26 国家工业信息安全发展研究中心 Data updating method and server

Similar Documents

Publication Publication Date Title
CN110019350B (en) Data query method and device based on configuration information
CN109189835B (en) Method and device for generating data wide table in real time
CN110764796A (en) Method and device for updating cache
US8495166B2 (en) Optimized caching for large data requests
US11256773B2 (en) Document online preview method and device
CN111865970B (en) Method and apparatus for implementing interface idempotency
CN111400061A (en) Data processing method and system
US11086827B1 (en) Dataset schema and metadata management service
CN111694857B (en) Method, device, electronic equipment and computer readable medium for storing resource data
CN110765187A (en) Data source route management method and device
WO2018177032A1 (en) Method and device for processing response data, client device and electronic device
CN111104479A (en) Data labeling method and device
CN109960212B (en) Task sending method and device
CN115455058A (en) Cache data processing method and device, computer equipment and storage medium
CN112783887A (en) Data processing method and device based on data warehouse
US9473561B2 (en) Data transmission for transaction processing in a networked environment
CN110705271B (en) System and method for providing natural language processing service
US10616291B2 (en) Response caching
CN115840956A (en) File processing method, device, server and medium
US11379268B1 (en) Affinity-based routing and execution for workflow service
CN113760861A (en) Data migration method and device
CN113220981A (en) Method and device for optimizing cache
CN113779122A (en) Method and apparatus for exporting data
CN113704242A (en) Data processing method and device
CN113626176A (en) Service request processing method and device

Legal Events

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