CN107124466B - Method and device for preventing cache from penetrating and computer readable storage medium - Google Patents

Method and device for preventing cache from penetrating and computer readable storage medium Download PDF

Info

Publication number
CN107124466B
CN107124466B CN201710372299.7A CN201710372299A CN107124466B CN 107124466 B CN107124466 B CN 107124466B CN 201710372299 A CN201710372299 A CN 201710372299A CN 107124466 B CN107124466 B CN 107124466B
Authority
CN
China
Prior art keywords
cache
value
null
server
data
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.)
Active
Application number
CN201710372299.7A
Other languages
Chinese (zh)
Other versions
CN107124466A (en
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.)
Nubia Technology Co Ltd
Original Assignee
Nubia 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 Nubia Technology Co Ltd filed Critical Nubia Technology Co Ltd
Priority to CN201710372299.7A priority Critical patent/CN107124466B/en
Publication of CN107124466A publication Critical patent/CN107124466A/en
Application granted granted Critical
Publication of CN107124466B publication Critical patent/CN107124466B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources

Abstract

The invention discloses a method and a device for preventing cache from penetrating and a computer readable storage medium, wherein the method comprises the following steps: the client requests cache information from the server, wherein the request comprises a key value; the server side receives the request and obtains a cache value from a server side cache system according to the key value; judging whether the obtained cache value is a null value; if the obtained cache value is not a null value, judging whether the obtained cache value is a null default value; and if the acquired cache value is a null default value, converting the null default value into null data and returning the null data to the client. According to the method and the device for preventing the cache from penetrating and the computer readable storage medium, malicious attacks are prevented by adding null value storage, and the influence on the database of the server side system is reduced; the main and standby caches are used for preventing data penetration under the condition that key values fail; and the writing command of the server side cache system is used, so that the database of the server side system cannot be requested simultaneously when the data is refreshed.

Description

Method and device for preventing cache from penetrating and computer readable storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for preventing cache from being penetrated, and a computer-readable storage medium.
Background
A general caching system caches queries according to keys, and if no corresponding value exists, the query should be searched by a back-end system (such as a database). If the value corresponding to the key does not exist, and the concurrent request amount for the key is large, a large stress is caused to the back-end system. This is called cache penetration.
When the cache server is restarted or a large number of caches are concentrated in a certain time period to be invalid, great pressure is brought to a back-end system when the cache server is invalid.
Therefore, an effective solution to the cache-crossing phenomenon is needed.
Disclosure of Invention
The invention mainly aims to provide a method and a device for preventing cache from penetrating and a computer readable storage medium, and aims to solve the problem of cache penetration.
In order to achieve the above object, a first aspect of the embodiments of the present invention provides a method for preventing cache from being penetrated, where the method includes:
a client requests cache information from a server, wherein the request comprises a key value;
the server receives the request and obtains a cache value from a server cache system according to the key value;
judging whether the obtained cache value is a null value;
if the obtained cache value is not a null value, judging whether the obtained cache value is a null default value;
and if the acquired cache value is a null default value, converting the null default value into null data and returning the null data to the client.
Further, the null default value includes a special symbol or a dedicated string.
Further, the method comprises the steps of:
if the obtained cache value is not an empty default value, judging whether the obtained cache value is an NX default value;
and if the acquired cache value is an NX default value, reading data from the standby cache system according to the key value, and returning the read data to the client.
Further, the method comprises the steps of:
and if the obtained cache value is not the NX default value, returning the obtained cache value to the client.
Further, the method comprises the steps of:
if the obtained cache value is a null value, calling a write command of the server-side cache system, and writing an NX default value into the server-side cache system;
judging whether the NX default value writing is successfully executed;
and if the NX default value is successfully written and executed, reading data from the server-side database, if the data read from the server-side database is not null, writing the data read from the server-side database into the server-side cache system and the standby cache system, and returning the data read from the server-side database to the client.
Further, the method comprises the steps of:
and if the NX default value is not successfully written and executed, reading data from the standby cache system and returning the read data to the client.
Further, the method comprises the steps of:
and if the data read from the server database is null, writing the null default value into the server cache system and the standby cache system, converting the null default value into null data, and returning the null data to the client.
Further, the effective time of the data in the standby cache system is longer than the effective time of the data in the server-side cache system.
Further, to achieve the above object, a second aspect of embodiments of the present invention provides an apparatus for preventing cache breakthrough, including: the cache penetration preventing program is stored on the memory and can run on the processor, and when being executed by the processor, the cache penetration preventing program realizes the steps of the cache penetration preventing method.
Furthermore, to achieve the above object, a third aspect of the embodiments of the present invention provides a computer-readable storage medium, where a cache breakthrough preventing program is stored, and the cache breakthrough preventing program, when executed by a processor, implements the steps of the above cache breakthrough preventing method.
According to the method and the device for preventing the cache from penetrating and the computer readable storage medium, malicious attacks are prevented by adding null value storage, and influences on a server end system database are reduced; the main and standby caches are used for preventing data penetration under the condition that key values fail; and the writing command of the server side cache system is used, so that the database of the server side system cannot be requested simultaneously when the data is refreshed.
Drawings
Fig. 1 is a schematic diagram of a hardware structure of a mobile terminal implementing various embodiments of the present invention;
fig. 2 is a diagram of a communication network system architecture according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for preventing cache breakthrough according to an embodiment of the present invention;
FIG. 4 is a schematic flow chart illustrating a method for preventing cache breakthrough according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a method for preventing cache breakthrough according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a device for preventing cache from penetrating according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the following description, suffixes such as "module", "component", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no specific meaning in itself. Thus, "module", "component" or "unit" may be used mixedly.
The terminal may be implemented in various forms. For example, the terminal described in the present invention may include a mobile terminal such as a mobile phone, a tablet computer, a notebook computer, a palmtop computer, a Personal Digital Assistant (PDA), a Portable Media Player (PMP), a navigation device, a wearable device, a smart band, a pedometer, and the like, and a fixed terminal such as a Digital TV, a desktop computer, and the like.
The following description will be given by way of example of a mobile terminal, and it will be understood by those skilled in the art that the construction according to the embodiment of the present invention can be applied to a fixed type terminal, in addition to elements particularly used for mobile purposes.
Referring to fig. 1, which is a schematic diagram of a hardware structure of a mobile terminal for implementing various embodiments of the present invention, the mobile terminal 100 may include: RF (Radio Frequency) unit 101, WiFi module 102, audio output unit 103, a/V (audio/video) input unit 104, sensor 105, display unit 106, user input unit 107, interface unit 108, memory 109, processor 110, and power supply 111. Those skilled in the art will appreciate that the mobile terminal architecture shown in fig. 1 is not intended to be limiting of mobile terminals, which may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
The following describes each component of the mobile terminal in detail with reference to fig. 1:
the radio frequency unit 101 may be configured to receive and transmit signals during information transmission and reception or during a call, and specifically, receive downlink information of a base station and then process the downlink information to the processor 110; in addition, the uplink data is transmitted to the base station. Typically, radio frequency unit 101 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, and the like. In addition, the radio frequency unit 101 can also communicate with a network and other devices through wireless communication. The wireless communication may use any communication standard or protocol, including but not limited to GSM (Global System for Mobile communications), GPRS (General Packet Radio Service), CDMA2000(Code Division Multiple Access 2000), WCDMA (Wideband Code Division Multiple Access), TD-SCDMA (Time Division-Synchronous Code Division Multiple Access), FDD-LTE (Frequency Division duplex Long Term Evolution), and TDD-LTE (Time Division duplex Long Term Evolution).
WiFi belongs to short-distance wireless transmission technology, and the mobile terminal can help a user to receive and send e-mails, browse webpages, access streaming media and the like through the WiFi module 102, and provides wireless broadband internet access for the user. Although fig. 1 shows the WiFi module 102, it is understood that it does not belong to the essential constitution of the mobile terminal, and may be omitted entirely as needed within the scope not changing the essence of the invention.
The audio output unit 103 may convert audio data received by the radio frequency unit 101 or the WiFi module 102 or stored in the memory 109 into an audio signal and output as sound when the mobile terminal 100 is in a call signal reception mode, a call mode, a recording mode, a voice recognition mode, a broadcast reception mode, or the like. Also, the audio output unit 103 may also provide audio output related to a specific function performed by the mobile terminal 100 (e.g., a call signal reception sound, a message reception sound, etc.). The audio output unit 103 may include a speaker, a buzzer, and the like.
The a/V input unit 104 is used to receive audio or video signals. The a/V input Unit 104 may include a Graphics Processing Unit (GPU) 1041 and a microphone 1042, the Graphics processor 1041 Processing image data of still pictures or video obtained by an image capturing device (e.g., a camera) in a video capturing mode or an image capturing mode. The processed image frames may be displayed on the display unit 106. The image frames processed by the graphic processor 1041 may be stored in the memory 109 (or other storage medium) or transmitted via the radio frequency unit 101 or the WiFi module 102. The microphone 1042 may receive sounds (audio data) via the microphone 1042 in a phone call mode, a recording mode, a voice recognition mode, or the like, and may be capable of processing such sounds into audio data. The processed audio (voice) data may be converted into a format output transmittable to a mobile communication base station via the radio frequency unit 101 in case of a phone call mode. The microphone 1042 may implement various types of noise cancellation (or suppression) algorithms to cancel (or suppress) noise or interference generated in the course of receiving and transmitting audio signals.
The mobile terminal 100 also includes at least one sensor 105, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor that can adjust the brightness of the display panel 1061 according to the brightness of ambient light, and a proximity sensor that can turn off the display panel 1061 and/or a backlight when the mobile terminal 100 is moved to the ear. As one of the motion sensors, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally, three axes), can detect the magnitude and direction of gravity when stationary, and can be used for applications of recognizing the posture of a mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer and tapping), and the like; as for other sensors such as a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor, which can be configured on the mobile phone, further description is omitted here.
The display unit 106 is used to display information input by a user or information provided to the user. The Display unit 106 may include a Display panel 1061, and the Display panel 1061 may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like.
The user input unit 107 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the mobile terminal. Specifically, the user input unit 107 may include a touch panel 1071 and other input devices 1072. The touch panel 1071, also referred to as a touch screen, may collect a touch operation performed by a user on or near the touch panel 1071 (e.g., an operation performed by the user on or near the touch panel 1071 using a finger, a stylus, or any other suitable object or accessory), and drive a corresponding connection device according to a predetermined program. The touch panel 1071 may include two parts of a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 110, and can receive and execute commands sent by the processor 110. In addition, the touch panel 1071 may be implemented in various types, such as a resistive type, a capacitive type, an infrared ray, and a surface acoustic wave. In addition to the touch panel 1071, the user input unit 107 may include other input devices 1072. In particular, other input devices 1072 may include, but are not limited to, one or more of a physical keyboard, function keys (e.g., volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like, and are not limited to these specific examples.
Further, the touch panel 1071 may cover the display panel 1061, and when the touch panel 1071 detects a touch operation thereon or nearby, the touch panel 1071 transmits the touch operation to the processor 110 to determine the type of the touch event, and then the processor 110 provides a corresponding visual output on the display panel 1061 according to the type of the touch event. Although the touch panel 1071 and the display panel 1061 are shown in fig. 1 as two separate components to implement the input and output functions of the mobile terminal, in some embodiments, the touch panel 1071 and the display panel 1061 may be integrated to implement the input and output functions of the mobile terminal, and is not limited herein.
The interface unit 108 serves as an interface through which at least one external device is connected to the mobile terminal 100. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device having an identification module, an audio input/output (I/O) port, a video I/O port, an earphone port, and the like. The interface unit 108 may be used to receive input (e.g., data information, power, etc.) from external devices and transmit the received input to one or more elements within the mobile terminal 100 or may be used to transmit data between the mobile terminal 100 and external devices.
The memory 109 may be used to store software programs as well as various data. The memory 109 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. Further, the memory 109 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
The processor 110 is a control center of the mobile terminal, connects various parts of the entire mobile terminal using various interfaces and lines, and performs various functions of the mobile terminal and processes data by operating or executing software programs and/or modules stored in the memory 109 and calling data stored in the memory 109, thereby performing overall monitoring of the mobile terminal. Processor 110 may include one or more processing units; preferably, the processor 110 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 110.
The mobile terminal 100 may further include a power supply 111 (e.g., a battery) for supplying power to various components, and preferably, the power supply 111 may be logically connected to the processor 110 via a power management system, so as to manage charging, discharging, and power consumption management functions via the power management system.
Although not shown in fig. 1, the mobile terminal 100 may further include a bluetooth module or the like, which is not described in detail herein.
In order to facilitate understanding of the embodiments of the present invention, a communication network system on which the mobile terminal of the present invention is based is described below.
Referring to fig. 2, fig. 2 is an architecture diagram of a communication Network system according to an embodiment of the present invention, where the communication Network system is an LTE system of a universal mobile telecommunications technology, and the LTE system includes a UE (User Equipment) 201, an E-UTRAN (Evolved UMTS Terrestrial Radio Access Network) 202, an EPC (Evolved Packet Core) 203, and an IP service 204 of an operator, which are in communication connection in sequence.
Specifically, the UE201 may be the terminal 100 described above, and is not described herein again.
The E-UTRAN202 includes eNodeB2021 and other eNodeBs 2022, among others. Among them, the eNodeB2021 may be connected with other eNodeB2022 through backhaul (e.g., X2 interface), the eNodeB2021 is connected to the EPC203, and the eNodeB2021 may provide the UE201 access to the EPC 203.
The EPC203 may include an MME (Mobility Management Entity) 2031, an HSS (Home Subscriber Server) 2032, other MMEs 2033, an SGW (Serving gateway) 2034, a PGW (PDN gateway) 2035, and a PCRF (Policy and Charging Rules Function) 2036, and the like. The MME2031 is a control node that handles signaling between the UE201 and the EPC203, and provides bearer and connection management. HSS2032 is used to provide registers to manage functions such as home location register (not shown) and holds subscriber specific information about service characteristics, data rates, etc. All user data may be sent through SGW2034, PGW2035 may provide IP address assignment for UE201 and other functions, and PCRF2036 is a policy and charging control policy decision point for traffic data flow and IP bearer resources, which selects and provides available policy and charging control decisions for a policy and charging enforcement function (not shown).
The IP services 204 may include the internet, intranets, IMS (IP Multimedia Subsystem), or other IP services, among others.
Although the LTE system is described as an example, it should be understood by those skilled in the art that the present invention is not limited to the LTE system, but may also be applied to other wireless communication systems, such as GSM, CDMA2000, WCDMA, TD-SCDMA, and future new network systems.
Based on the above mobile terminal hardware structure and communication network system, the present invention provides various embodiments of the method.
First embodiment
As shown in fig. 3, a first embodiment of the present invention provides a method for preventing cache breakthrough, including the steps of:
31. the client requests the cache information from the server, wherein the request comprises a key value.
32. And the server receives the request and obtains a cache value from a server cache system according to the key value.
In this embodiment, the server-side cache system may be a Redis cache system or a cache system similar thereto. Redis is a high-performance Key-Value database.
33. And judging whether the obtained cache value is a null value.
34. If the obtained cache value is not a null value, judging whether the obtained cache value is a null default value;
35. and if the acquired cache value is a null default value, converting the null default value into null data and returning the null data to the client.
In this embodiment, the null default value includes a special symbol or a dedicated string. The empty default value indicates that the key value has no corresponding service data.
For example: caching data according to the user ID, wherein the user ID uploaded by the client does not exist in a database of the server end system; because data does not exist, if the data is not inserted into the cache, multiple requests of the client side penetrate through the cache and directly reach the server side system, and pressure is caused on the server side system including a database and the like.
Therefore, in the embodiment, by setting the empty default value to be inserted into the key value corresponding to the cache under the condition that the service data does not exist, cache penetration can be avoided, malicious attack is prevented, and the influence on the database of the back-end system is reduced.
Referring to fig. 4, in one embodiment, the method further includes the steps of:
341. if the obtained cache value is not an empty default value, judging whether the obtained cache value is an NX default value;
in this embodiment, taking the Redis cache system as an example, the NX default value represents a default value inserted when the Setnx operation of the Redis is executed, and represents that the value is being written.
342. And if the acquired cache value is an NX default value, reading data from the standby cache system according to the key value, and returning the read data to the client.
In this embodiment, the key value in the standby cache system is different from the key value in the server-side cache system, and specifically may be "key value in server-side cache system" + "backache".
In this embodiment, data penetration is prevented from occurring in the event of a key value failure by using the primary and secondary caches.
Referring to fig. 4 again, further, the method further includes the steps of:
343. and if the obtained cache value is not the NX default value, returning the obtained cache value to the client.
Referring to fig. 5, in another embodiment, the method further includes the steps of:
331. if the obtained cache value is a null value, calling a write command of the server-side cache system, and writing an NX default value into the server-side cache system;
taking the Redis cache system as an example, if the obtained cache value is null, a Setnx or Hsetnx command of the Redis cache system can be called, and the NX default value is written into the Redis cache system.
In the embodiment, the write command of the server-side cache system is used to ensure that the database of the server-side system is not requested at the same time when the data is refreshed
332. Judging whether the NX default value writing is successfully executed;
taking Redis cache system as an example, by judging whether the Setnx command is successfully executed or not, the success of execution returns 1, and the failure returns 0.
333. And if the NX default value is successfully written and executed, reading data from the server-side database, if the data read from the server-side database is not null, writing the data read from the server-side database into the server-side cache system and the standby cache system, and returning the data read from the server-side database to the client.
In this embodiment, the valid time of the data in the standby cache system is longer than the valid time of the data in the server-side cache system. For example: the effective time of the data in the standby cache system is set to be 10 minutes longer than that of the data in the server-side cache system. And when the cache system of the server side fails, the data cannot directly penetrate through the database of the server side system.
Further, the method comprises the steps (not shown in the figures):
and if the data read from the server database is null, writing the null default value into the server cache system and the standby cache system, converting the null default value into null data, and returning the null data to the client.
Further, the method comprises the steps (not shown in the figures):
and if the NX default value is not successfully written and executed, reading data from the standby cache system and returning the read data to the client.
According to the method for preventing cache penetration, malicious attack is prevented by adding null value storage, and influence on a database of a server end system is reduced; the main and standby caches are used for preventing data penetration under the condition that key values fail; and the writing command of the server side cache system is used, so that the database of the server side system cannot be requested simultaneously when the data is refreshed.
Second embodiment
Referring to fig. 6, fig. 6 is a diagram illustrating an apparatus for preventing cache breakthrough according to a second embodiment of the present invention, where the apparatus 40 for preventing cache breakthrough includes: a memory 41, a processor 42 and a cache breakthrough prevention program stored on the memory 41 and executable on the processor 42, the cache breakthrough prevention program, when executed by the processor 42, implementing the steps of the cache breakthrough prevention method.
Specifically, the following steps of the method for preventing cache penetration are implemented:
a client requests cache information from a server, wherein the request comprises a key value;
the server receives the request and obtains a cache value from a server cache system according to the key value;
judging whether the obtained cache value is a null value;
if the obtained cache value is not a null value, judging whether the obtained cache value is a null default value;
and if the acquired cache value is a null default value, converting the null default value into null data and returning the null data to the client.
In this embodiment, by setting the null default value to be inserted into the key value corresponding to the cache, cache penetration can be avoided, malicious attack is prevented, and the influence on the database of the backend system is reduced.
In one embodiment, the cache penetration prevention program, when executed by the processor 42, is further configured to:
if the obtained cache value is not an empty default value, judging whether the obtained cache value is an NX default value;
and if the acquired cache value is an NX default value, reading data from the standby cache system according to the key value, and returning the read data to the client.
And if the obtained cache value is not the NX default value, returning the obtained cache value to the client.
In this embodiment, data penetration is prevented from occurring in the event of a key value failure by using the primary and secondary caches.
In another embodiment, the cache penetration prevention program, when executed by the processor 42, is further configured to:
if the obtained cache value is a null value, calling a write command of the server-side cache system, and writing an NX default value into the server-side cache system;
judging whether the NX default value writing is successfully executed;
and if the NX default value is successfully written and executed, reading data from the server-side database, if the data read from the server-side database is not null, writing the data read from the server-side database into the server-side cache system and the standby cache system, and returning the data read from the server-side database to the client.
And if the NX default value is not successfully written and executed, reading data from the standby cache system and returning the read data to the client.
And if the data read from the server database is null, writing the null default value into the server cache system and the standby cache system, converting the null default value into null data, and returning the null data to the client.
In the embodiment, the write command of the server-side cache system is used to ensure that the database of the server-side system is not requested at the same time when the data is refreshed
According to the device for preventing cache penetration, malicious attack is prevented by adding null value storage, and the influence on a database of a server end system is reduced; the main and standby caches are used for preventing data penetration under the condition that key values fail; and the writing command of the server side cache system is used, so that the database of the server side system cannot be requested simultaneously when the data is refreshed.
Third embodiment
A third embodiment of the present invention provides a computer-readable storage medium having a cache breakthrough prevention program stored thereon, which, when executed by a processor, implements the steps of the cache breakthrough prevention method.
Specifically, the following steps of the method for preventing cache penetration are implemented:
a client requests cache information from a server, wherein the request comprises a key value;
the server receives the request and obtains a cache value from a server cache system according to the key value;
judging whether the obtained cache value is a null value;
if the obtained cache value is not a null value, judging whether the obtained cache value is a null default value;
and if the acquired cache value is a null default value, converting the null default value into null data and returning the null data to the client.
In this embodiment, by setting the null default value to be inserted into the key value corresponding to the cache, cache penetration can be avoided, malicious attack is prevented, and the influence on the database of the backend system is reduced.
In one embodiment, the program for preventing cache from being penetrated realizes the following steps of the method for preventing cache from being penetrated when being executed by a processor:
if the obtained cache value is not an empty default value, judging whether the obtained cache value is an NX default value;
and if the acquired cache value is an NX default value, reading data from the standby cache system according to the key value, and returning the read data to the client.
And if the obtained cache value is not the NX default value, returning the obtained cache value to the client.
In this embodiment, data penetration is prevented from occurring in the event of a key value failure by using the primary and secondary caches.
In another embodiment, the program for preventing cache from being penetrated realizes the following steps of the method for preventing cache from being penetrated when being executed by a processor:
if the obtained cache value is a null value, calling a write command of the server-side cache system, and writing an NX default value into the server-side cache system;
judging whether the NX default value writing is successfully executed;
and if the NX default value is successfully written and executed, reading data from the server-side database, if the data read from the server-side database is not null, writing the data read from the server-side database into the server-side cache system and the standby cache system, and returning the data read from the server-side database to the client.
And if the NX default value is not successfully written and executed, reading data from the standby cache system and returning the read data to the client.
And if the data read from the server database is null, writing the null default value into the server cache system and the standby cache system, converting the null default value into null data, and returning the null data to the client.
In the embodiment, the write command of the server-side cache system is used to ensure that the database of the server-side system is not requested at the same time when the data is refreshed
According to the computer-readable storage medium provided by the embodiment of the invention, malicious attacks are prevented and the influence on the database of the server end system is reduced by newly adding null value storage; the main and standby caches are used for preventing data penetration under the condition that key values fail; and the writing command of the server side cache system is used, so that the database of the server side system cannot be requested simultaneously when the data is refreshed.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (9)

1. A method of preventing cache breakthrough, the method comprising the steps of:
a client requests cache information from a server, wherein the request comprises a key value;
the server receives the request and obtains a cache value from a server cache system according to the key value;
judging whether the obtained cache value is a null value;
if the obtained cache value is not a null value, judging whether the obtained cache value is a null default value;
if the obtained cache value is a null default value, converting the null default value into null data and returning the null data to the client;
if the obtained cache value is a null value, calling a write command of the server-side cache system, and writing an NX default value into the server-side cache system;
judging whether the NX default value writing is successfully executed;
and if the NX default value is successfully written and executed, reading data from the server-side database, if the data read from the server-side database is not null, writing the data read from the server-side database into the server-side cache system and the standby cache system, and returning the data read from the server-side database to the client.
2. The method of claim 1, wherein the null default value comprises a special symbol or a special string.
3. The method of claim 1, wherein the method further comprises the steps of:
if the obtained cache value is not an empty default value, judging whether the obtained cache value is an NX default value;
and if the acquired cache value is an NX default value, reading data from the standby cache system according to the key value, and returning the read data to the client.
4. A method for preventing cache penetration as recited in claim 3, wherein the method further comprises the steps of:
and if the obtained cache value is not the NX default value, returning the obtained cache value to the client.
5. The method of claim 1, wherein the method further comprises the steps of:
and if the NX default value is not successfully written and executed, reading data from the standby cache system and returning the read data to the client.
6. The method of claim 1, wherein the method further comprises the steps of:
and if the data read from the server database is null, writing null default values into the server cache system and the standby cache system, converting the null default values into null data, and returning the null data to the client.
7. The method according to claim 1, wherein the data in the backup cache system has a longer validity time than the data in the server-side cache system.
8. An apparatus for preventing cache breakthrough, wherein the apparatus for preventing cache breakthrough comprises: a memory, a processor and a cache penetration prevention program stored on the memory and executable on the processor, the cache penetration prevention program when executed by the processor implementing the steps of the cache penetration prevention method according to any one of claims 1 to 7.
9. A computer-readable storage medium, having a cache penetration prevention program stored thereon, which, when executed by a processor, implements the steps of the cache penetration prevention method according to any one of claims 1 to 7.
CN201710372299.7A 2017-05-23 2017-05-23 Method and device for preventing cache from penetrating and computer readable storage medium Active CN107124466B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710372299.7A CN107124466B (en) 2017-05-23 2017-05-23 Method and device for preventing cache from penetrating and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710372299.7A CN107124466B (en) 2017-05-23 2017-05-23 Method and device for preventing cache from penetrating and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN107124466A CN107124466A (en) 2017-09-01
CN107124466B true CN107124466B (en) 2020-12-29

Family

ID=59730167

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710372299.7A Active CN107124466B (en) 2017-05-23 2017-05-23 Method and device for preventing cache from penetrating and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN107124466B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110019366A (en) * 2017-12-21 2019-07-16 北京京东尚科信息技术有限公司 A kind of data cached method and apparatus
CN109710644A (en) * 2018-12-26 2019-05-03 苏州思必驰信息科技有限公司 The method and apparatus for preventing caching from penetrating
CN110109956B (en) * 2019-03-21 2021-10-01 福建天泉教育科技有限公司 Method and terminal for preventing cache from penetrating
CN113282621A (en) * 2021-04-23 2021-08-20 北京皮尔布莱尼软件有限公司 Processing method of cache data and computing equipment
CN114116796A (en) * 2021-11-02 2022-03-01 浪潮云信息技术股份公司 Distributed cache system for preventing cache treading

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103514106A (en) * 2012-06-20 2014-01-15 北京神州泰岳软件股份有限公司 Method for caching data
CN104281668A (en) * 2014-09-28 2015-01-14 墨仕(厦门)电子商务有限公司 Data processing method
CN105354151A (en) * 2014-08-19 2016-02-24 阿里巴巴集团控股有限公司 Cache management method and device
CN105554106A (en) * 2015-12-15 2016-05-04 上海仪电(集团)有限公司 Memcache distributed caching system
US9369332B1 (en) * 2013-02-27 2016-06-14 Amazon Technologies, Inc. In-memory distributed cache
CN106126673A (en) * 2016-06-29 2016-11-16 上海浦东发展银行股份有限公司信用卡中心 A kind of based on Redis and HBase point of locking method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103514106A (en) * 2012-06-20 2014-01-15 北京神州泰岳软件股份有限公司 Method for caching data
US9369332B1 (en) * 2013-02-27 2016-06-14 Amazon Technologies, Inc. In-memory distributed cache
CN105354151A (en) * 2014-08-19 2016-02-24 阿里巴巴集团控股有限公司 Cache management method and device
CN104281668A (en) * 2014-09-28 2015-01-14 墨仕(厦门)电子商务有限公司 Data processing method
CN105554106A (en) * 2015-12-15 2016-05-04 上海仪电(集团)有限公司 Memcache distributed caching system
CN106126673A (en) * 2016-06-29 2016-11-16 上海浦东发展银行股份有限公司信用卡中心 A kind of based on Redis and HBase point of locking method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
缓存系列文章--5.缓存穿透问题;carlosfu;《https://www.iteye.com/blog/carlosfu-2248185》;20151011;3-10 *

Also Published As

Publication number Publication date
CN107124466A (en) 2017-09-01

Similar Documents

Publication Publication Date Title
CN107124466B (en) Method and device for preventing cache from penetrating and computer readable storage medium
CN107038245B (en) Page switching method, mobile terminal and storage medium
CN109195143B (en) Network access method, mobile terminal and readable storage medium
CN107317855B (en) Data caching method, data requesting method and server
CN107862217B (en) Position information acquisition method, mobile terminal and computer storage medium
CN110180181B (en) Method and device for capturing wonderful moment video and computer readable storage medium
CN110187925B (en) Desktop pre-starting control method, device and computer readable storage medium
CN109766119B (en) Recovery partition upgrade method, terminal and computer readable storage medium
CN107818022B (en) Application program interface merging method, mobile terminal and computer readable storage medium
CN112597115A (en) Container mirror image compression method and device, terminal equipment and medium
CN109151216B (en) Application starting method, mobile terminal, server and computer readable storage medium
CN107809527B (en) Method for presenting shortcut operation and electronic equipment
CN107194217B (en) User data access control method, apparatus and computer-readable storage medium
CN111970738A (en) Network switching control method, equipment and computer readable storage medium
CN109683796B (en) Interaction control method, equipment and computer readable storage medium
CN109062688B (en) Memory allocation method, server and mobile terminal
CN108183833B (en) Response processing method and device and computer readable storage medium
CN109257739B (en) eSIM card operation method, mobile terminal and eSIM card device
CN107404568B (en) Control switch management method and mobile terminal
CN110955397A (en) Method for setting frame rate of game terminal, game terminal and storage medium
CN107153688B (en) Data query method, equipment and computer storage medium
CN114253687A (en) Multi-window leakage processing method and device and computer readable storage medium
CN109725808B (en) Interaction control method, equipment and computer readable storage medium
CN109379719B (en) Application program broadcast processing method and device and computer readable storage medium
CN108304302B (en) Interface merging method, equipment and computer readable storage medium

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
GR01 Patent grant
GR01 Patent grant