WO2020211372A1 - 数据的缓存方法、装置、计算机设备 - Google Patents

数据的缓存方法、装置、计算机设备 Download PDF

Info

Publication number
WO2020211372A1
WO2020211372A1 PCT/CN2019/119216 CN2019119216W WO2020211372A1 WO 2020211372 A1 WO2020211372 A1 WO 2020211372A1 CN 2019119216 W CN2019119216 W CN 2019119216W WO 2020211372 A1 WO2020211372 A1 WO 2020211372A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
thread
service data
data
timestamp
Prior art date
Application number
PCT/CN2019/119216
Other languages
English (en)
French (fr)
Inventor
李文斌
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020211372A1 publication Critical patent/WO2020211372A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Definitions

  • This application relates to the field of cloud storage technology, and in particular to a data caching method, device, and computer equipment.
  • this application proposes a data caching method, device, and computer equipment, which aims to solve the problem of too many links to the server, occupying too much resources, reducing storage efficiency, and causing server downtime.
  • a method for caching data includes:
  • Release the waiting state of the second thread return the first target service data in the first cache segment to the second thread, and obtain back-end service data to obtain second target service data, And get the current time, get the second timestamp;
  • This application also provides a data caching device, which includes:
  • the receiving module is used to receive requests from the first thread and the second thread to obtain the same service data concurrently;
  • the search module is used to search for the business data in the cache fragment collection
  • the locking module is used to lock the back-end service data if the service data is not found, and lock the first thread and the second thread through competition, and the thread that successfully locks is allowed to obtain the back-end Business data;
  • the identification module is used to identify whether there is a thread successfully locked in the first thread and the second thread;
  • An adjustment module configured to adjust the second thread to a waiting state if it is recognized that the first thread is successfully locked
  • the first obtaining module is configured to obtain back-end service data through the first thread, obtain the first target service data, obtain the current time, obtain the first time stamp, and return the first target service data to the first One thread
  • the first calculation module is configured to calculate the cache fragment corresponding to the first time stamp in the cache fragment set by using a Hash algorithm to obtain the first cache fragment;
  • a first writing module configured to write the first time stamp and the first target service data into the first cache segment, and unlock the back-end service data
  • the second acquisition module is configured to release the waiting state of the second thread, return the first target service data in the first cache segment to the second thread, and obtain back-end service data, Obtain the second target business data, obtain the current time, and obtain the second timestamp;
  • a second calculation module configured to calculate the cache fragment corresponding to the second timestamp in the cache fragment set by using the Hash algorithm to obtain the second cache fragment;
  • the second writing module is configured to write the second time stamp and the second target service data into the second cache segment.
  • the present application also provides a computer device, including a memory and a processor, the memory stores a computer program, and the processor implements the steps of any one of the foregoing methods when the computer program is executed.
  • the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the above methods are implemented.
  • the first thread and the second thread concurrently request the same business data. If the business data is not found in the cache shard set, let the first thread and the second thread compete for the lock and obtain the business data from the backend. The thread competition succeeds, the back-end business data is locked, only the first thread is allowed to obtain the business data, the business data is obtained in the first thread, and the corresponding first target business data and first timestamp are written into the corresponding The first cache fragment, and then unlock the back-end business data, the second thread obtains the first target business data from the first cache fragment, and then writes the corresponding second target business data and second timestamp to the corresponding
  • the second cache fragmentation solves the problem of too many links to the server and too much resource usage, which reduces storage efficiency and causes server downtime.
  • FIG. 1 is a flowchart of a method for caching data provided by an embodiment of the present application
  • FIG. 2 is a functional module diagram of a caching device using data provided by an embodiment of the present application
  • Fig. 3 is a schematic block diagram of the structure of a computer device provided by an embodiment of the present application.
  • an embodiment of the present application proposes a data caching method, and the method includes the following steps:
  • Step S101 Receive requests from the first thread and the second thread to concurrently obtain the same service data.
  • the concurrency can be at the same time point or within the same time period.
  • the first thread and the second thread both initiate requests at 15:00. This is the same time point.
  • the second thread can be a single thread or multiple threads.
  • multiple threads may concurrently obtain the same service data.
  • the multiple threads include the first thread, the second thread, and other threads, and the processing manner of the other threads is the same as that of the second thread.
  • Step S102 Search for the service data in the cache fragment set.
  • the first thread and the second thread request business data, first search in the cache shard collection, if not found, then go to the back end to search for the corresponding business data.
  • the cache shard set is a set that includes multiple cache shards, and the multiple cache shards are distributed.
  • Step S103 If the service data is not found, lock the back-end service data, and lock the first thread and the second thread through competition, and the thread that successfully locks is allowed to obtain the back-end service data.
  • the first thread and the second thread cannot request business data from the backend, so that the first thread and the second thread compete for a lock, and the contention for the lock is allowed
  • the thread requests business data from the backend and locks the business data on the backend.
  • Other threads are not allowed to request business data from the backend, that is, threads that have not competed for the lock cannot request business data from the backend.
  • Step S104 Identify whether there is a thread successfully locked in the first thread and the second thread.
  • Identify whether the back-end business data is locked If the back-end business data is locked, then identify whether the first thread or the second thread locks the back-end business data, and the thread that locks the back-end business data has a lock Identification, by identifying the lock identification, it is determined whether it is the first thread or the second thread that locks the back-end business data.
  • Step S105 If it is recognized that the first thread is successfully locked, adjust the second thread to a waiting state.
  • the other thread needs to be adjusted to the equal state, that is, the thread is not allowed to request service data from the backend. Specifically, if the first thread successfully locks, the second thread is adjusted to the waiting state, and if the second thread successfully locks, the first thread is adjusted to the waiting state.
  • Step S106 Obtain back-end service data through the first thread, obtain the first target service data, obtain the current time, and obtain the first time stamp.
  • the first thread obtains business data through the backend.
  • it needs to write the backend business data to the cache shard set and record the time of the backend business data. Get the current time and get the first timestamp.
  • Step S107 Calculate the cache fragment corresponding to the first time stamp in the cache fragment set by using the Hash algorithm to obtain the first cache fragment.
  • a shard id is set for each cache shard in the cache shard set, and a shard id is calculated for each timestamp through the Hash algorithm, so that the corresponding cache shard can be found in the cache shard set.
  • Step S108 Write the first time stamp and the first target service data into the first cache segment, and unlock the back-end service data.
  • the locking of the first thread After the first time stamp and the first target service data are written into the first cache segment, the locking of the first thread has ended, the lock on the back-end service data is released, and other threads are allowed to request and obtain the back-end service data.
  • Step S109 Release the waiting state of the second thread, return the first target service data in the first cache segment to the second thread, and obtain back-end service data to obtain the second target Business data, and get the current time, get the second timestamp.
  • the waiting state of the second thread is released, and the second thread searches for business data in the cache shard set again.
  • the cache shard set stores business data
  • the second thread finds the business data in the first cache shard. That is, the first target business data, the first target business data is obtained from the first cache segment.
  • the back-end business data may be updated, and the business data needs to be obtained from the back-end.
  • a new thread is added to obtain the back-end business data and the timestamp corresponding to the business data at this time.
  • Step S110 Calculate the cache fragment corresponding to the second timestamp in the cache fragment set through the Hash algorithm, and obtain a second cache fragment.
  • Step S111 Write the second time stamp and the second target service data into the second cache segment.
  • the corresponding cache segment is calculated through the Hash algorithm, and then the second timestamp and the second target business data are written into the corresponding cache segment.
  • the corresponding cache segment is the second cache segment. In this way, subsequent threads Not only can business data be obtained in the cache shard collection, but also business data that may be updated.
  • step S111 the method includes:
  • the third thread initiates a request for obtaining service data after the first thread and the second thread request the service data harness.
  • the business data of the second cache segment is the second target business data. After the third thread obtains the second target business data from the second cache segment, it also needs to obtain the business data and the corresponding timestamp from the backend. Then, the business data at this time and the corresponding timestamp are written into the corresponding cache shards, so that subsequent threads can not only obtain the business data in the cache shard collection, but also obtain the possibly updated business data.
  • step S111 the method includes:
  • the last modification time is the latest time, acquiring back-end business data, acquiring the sixth target business data, acquiring the current time, and acquiring the sixth time stamp;
  • the back-end service data is not obtained and written into the corresponding cache segment.
  • the fourth thread initiates a request for obtaining service data after the first thread and the second thread request the service data harness.
  • After the fourth thread obtains the business data instead of obtaining the business data directly from the backend, it first obtains the last modification time of the business data from the backend. The last modification time is compared with the time of the second timestamp.
  • the last modification time is It is the latest, indicating that the back-end business data has been updated, and then the business data needs to be obtained from the back-end. If the time of the second timestamp is the latest, it means that the back-end business data has not been updated, so there is no need to obtain business from the back-end Data, reduce the number of times to obtain business data from the backend, and reduce the number of times that business data is written to the cache shard collection.
  • step S102 the method includes:
  • the cache segment where the business data is located is a cache segment, returning the business data in the one cache segment to the first thread and the second thread;
  • business data is stored in the cache shard set, and only one cache shard stores business data
  • the business data is obtained from the corresponding cache shard in the cache shard set and returned to the first thread and the second thread.
  • the business data and the corresponding timestamp need to be obtained from the backend, and then the business data and the corresponding timestamp at this time are written into the corresponding cache segment.
  • the method After the step of searching the cache segment where the service data is located if the service data is found, the method includes:
  • the cache segment where the service data is located is multiple cache segments, obtain the corresponding timestamp from the multiple cache segments;
  • the method before the step of releasing the waiting state of the second thread, the method includes:
  • a release instruction is generated, and the instruction is executed to release the waiting state of the second thread.
  • the method includes:
  • the method Before the step of releasing the waiting state of the second thread, the method includes:
  • the first thread and the second thread concurrently request the same business data. If the business data is not found in the cache shard set, let the first thread and the second thread compete for the lock, and proceed from the back-end business data. Obtain, if the first thread competes successfully, lock the back-end business data, only allow the first thread to obtain the business data, obtain the business data in the first thread, and add the corresponding first target business data and the first time The stamp is written into the corresponding first cache segment, and then the back-end business data is unlocked.
  • the second thread obtains the first target business data from the first cache segment, and then transfers the corresponding second target business data and the second time Stamping into the corresponding second cache segment solves the problem of too many links to the server and too much resource usage, which reduces storage efficiency and causes server downtime.
  • an embodiment of the present application proposes a data caching device 1.
  • the device 1 includes a receiving module 11, a search module 12, a locking module 13, an identification module 14, an adjustment module 15, a first acquisition module 16, and a second A calculation module 17, a first write module 18, a second acquisition module 19, a second calculation module 20, and a second write module 21.
  • the receiving module 11 is configured to receive requests from the first thread and the second thread to concurrently obtain the same service data.
  • the search module 12 is used to search for the business data in the cache fragment set.
  • the locking module 13 is configured to lock the back-end service data if the service data is not found, and lock the first thread and the second thread through competition, where the thread that successfully locks is allowed to obtain Business data.
  • the identification module 14 is configured to identify whether there is a thread successfully locked in the first thread and the second thread.
  • the adjustment module 15 is configured to adjust the second thread to a waiting state if it is recognized that the first thread is successfully locked.
  • the first obtaining module 16 is configured to obtain back-end service data through the first thread, obtain the first target service data, obtain the current time, and obtain the first time stamp.
  • the first calculation module 17 is configured to calculate the cache fragment corresponding to the first time stamp in the cache fragment set by using the Hash algorithm to obtain the first cache fragment.
  • the first writing module 18 is configured to write the first timestamp and the first target service data into the first cache segment, and unlock the back-end service data.
  • the second acquisition module 19 is configured to release the waiting state of the second thread, return the first target business data in the first cache segment to the second thread, and acquire back-end business data To obtain the second target business data, and obtain the current time, and obtain the second time stamp.
  • the second calculation module 20 is configured to calculate the cache fragment corresponding to the second timestamp in the cache fragment set by using the Hash algorithm to obtain a second cache fragment.
  • the second writing module 21 is configured to write the second time stamp and the second target service data into the second cache segment.
  • the device 1 includes:
  • the first receiving module is configured to receive a request from a third thread to obtain the service data
  • the first search module is configured to search for the business data in a set of cache fragments, and find that the cache fragments where the business data is located are the first cache fragment and the second cache fragment;
  • a third obtaining module configured to obtain the first time stamp from the first cache fragment, and obtain the second time stamp from the second cache fragment;
  • a first comparison module configured to compare the first time stamp with the second time stamp, and determine that the time of the second time stamp is the latest according to the comparison result
  • a first sending module configured to return the second target service data in the second cache segment to the third thread
  • the fourth acquiring module is used to acquire back-end business data, acquire third target business data, acquire the current time, and acquire the third timestamp;
  • a third calculation module configured to calculate the cache fragment corresponding to the third timestamp in the cache fragment set by using the Hash algorithm to obtain the third cache fragment;
  • the third writing module is configured to write the third time stamp and the third target service data into the third cache segment.
  • the device 1 includes:
  • the second receiving module is configured to receive a request from the fourth thread to obtain the service data
  • the second search module is configured to search for the business data in a set of cache fragments, and find that the cache fragments where the business data is located are the first cache fragment and the second cache fragment;
  • a fourth obtaining module configured to obtain the first time stamp from the first cache fragment, and obtain the second time stamp from the second cache fragment;
  • a second comparison module configured to compare the first time stamp with the second time stamp, and determine that the time of the second time stamp is the latest according to the comparison result
  • a fifth obtaining module configured to return the second target service data in the second cache segment to the third thread, and obtain the last modification time of the back-end service data
  • a third comparison module configured to compare the last modified time with the time of the second time stamp
  • the sixth obtaining module is configured to obtain the back-end service data, obtain the sixth target service data, obtain the current time, and obtain the sixth time stamp if the last modification time is the latest time;
  • a fourth calculation module configured to calculate the cache fragment corresponding to the sixth timestamp in the cache fragment set by using the Hash algorithm to obtain the sixth cache fragment;
  • a fourth writing module configured to write the sixth time stamp and the sixth target service data into the third cache segment
  • the first rejection module is configured to, if the second timestamp is the latest time, do not obtain back-end service data and write it into the corresponding cache segment.
  • the device 1 includes:
  • the third searching module is configured to search for the cache segment where the service data is located if the service data is found;
  • the second sending module is configured to, if the cache segment where the service data is located is a cache segment, return the service data in the one cache segment to the first thread and the second thread;
  • the seventh obtaining module is used to obtain back-end service data, obtain fourth target service data, obtain the current time, and obtain the fourth time stamp;
  • a fifth calculation module configured to calculate the cache fragment corresponding to the fourth timestamp in the cache fragment set by using the Hash algorithm to obtain the fourth cache fragment;
  • the fifth writing module is configured to write the fourth time stamp and the fourth target service data into the fourth cache segment.
  • Device 1 includes:
  • An eighth obtaining module configured to obtain a corresponding timestamp from the multiple cache shards if the cache shard where the service data is located is multiple cache shards;
  • the fourth comparison module is configured to compare multiple time stamps, determine that the time of one of the multiple time stamps is the latest based on the comparison result, and obtain the target time stamp;
  • a third sending module configured to return the business data in the cache segment corresponding to the target timestamp to the first thread and the second thread;
  • the ninth acquiring module is used to acquire back-end business data, acquire fifth target business data, acquire the current time, and acquire the fifth timestamp;
  • a sixth calculation module configured to calculate the cache fragment corresponding to the fifth timestamp in the cache fragment set by using the Hash algorithm to obtain the fifth cache fragment;
  • the sixth writing module is configured to write the fifth time stamp and the fifth target service data into the fifth cache segment.
  • the device 1 includes:
  • the first detection module is configured to detect whether there is data writing in the first cache segment
  • the second detection module is configured to, if there is data writing, then detect whether the data writing is finished;
  • the first generating module is configured to generate an instruction to release the waiting state of the second thread if it ends.
  • the device 1 includes:
  • the first adding module is used to add a time lock to the second thread.
  • Device 1 includes:
  • the first judgment module is used to judge whether the time lock is invalid
  • the second generation module is configured to generate an instruction to release the waiting state of the second thread if the time lock fails.
  • an embodiment of the present application also provides a computer device.
  • the computer device may be a server, and its internal structure may be as shown in FIG. 3.
  • the computer equipment includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the computer designed processor is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, a computer program, and a database.
  • the memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the database of the computer equipment is used to store data such as the model of the data caching method.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the computer program is executed by the processor to realize a data caching method.
  • An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, a method for caching data is implemented.
  • the computer-readable storage medium is, for example, a non-volatile computer-readable storage medium or a volatile computer-readable storage medium.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

一种数据的缓存方法、装置、计算机设备,涉及云存储技术领域。第一线程和第二线程并发对同一业务数据进行请求获取,如果在缓存分片集合没有查找到业务数据,那么让第一线程和第二线程竞争锁,从后端的业务数据进行获取,如果第一线程竞争成功,对后端的业务数据进行加锁,只允许第一线程对业务数据获取,在第一线程获取到业务数据,并将对应的第一目标业务数据、第一时间戳写入对应的第一缓存分片,之后对后端的业务数据进行解锁,第二线程从第一缓存分片中获取第一目标业务数据,之后将对应的第二目标业务数据、第二时间戳写入对应的第二缓存分片,解决服务器的链接太多,占用资源过多,使得存储效率下降,导致服务器宕机的问题。

Description

数据的缓存方法、装置、计算机设备
本申请要求于2019年4月16日提交中国专利局、申请号为2019103058327,申请名称为“数据的缓存方法、装置、计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及云存储技术领域,特别涉及一种数据的缓存方法、装置、计算机设备。
背景技术
在多个线程并发请求访问接口,获取后端数据,会导致服务器的链接太多,占用资源过多,使得存储效率下降,进而导致服务器宕机的问题。
技术问题
针对现有技术不足,本申请提出一种数据的缓存方法、装置、计算机设备,旨在解决服务器的链接太多,占用资源过多,使得存储效率下降,进而导致服务器宕机的问题。
技术解决方案
本申请提出的技术方案是:
一种数据的缓存方法,所述方法包括:
接收第一线程、第二线程并发获取同一业务数据的请求;
在缓存分片集合中查找所述业务数据;
若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳;
通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
本申请还提供一种数据的缓存装置,所述装置包括:
接收模块,用于接收第一线程、第二线程并发获取同一业务数据的请求;
查找模块,用于在缓存分片集合中查找所述业务数据;
加锁模块,用于若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
识别模块,用于识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
调整模块,用于若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
第一获取模块,用于通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳,将所述第一目标业务数据返给所述第一线程;
第一计算模块,用于通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
第一写入模块,用于将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
第二获取模块,用于解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
第二计算模块,用于通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
第二写入模块,用于将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
本申请还提供一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述任一项所述的方法的步骤。
本申请还提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述任一项所述的方法的步骤。
有益效果
第一线程和第二线程并发对同一业务数据进行请求获取,如果在缓存分片集合没有查找业务数据,那么让第一线程和第二线程竞争锁,从后端的业务数据进行获取,如果第一线程竞争成功,对后端的业务数据进行加锁,只允许第一线程对业务数据获取,在第一线程获取到业务数据,并将对应的第一目标业务数据、第一时间戳写入对应的第一缓存分片,之后对后端的业务数据进行解锁,第二线程从第一缓存分片中获取第一目标业务数据,之后将对应的第二目标业务数据、第二时间戳写入对应的第二缓存分片,解决服务器的链接太多,占用资源过多,使得存储效率下降,进而导致服务器宕机的问题。
附图说明
图1是应用本申请实施例提供的数据的缓存方法的流程图;
图2是应用本申请实施例提供的数据的缓存装置的功能模块图;
图3是应用本申请实施例提供的计算机设备的结构示意框图。
本发明的最佳实施方式
如图1所示,本申请实施例提出一种数据的缓存方法,所述方法包括以下步骤:
步骤S101、接收第一线程、第二线程并发获取同一业务数据的请求。
在本实施例中,并发可以是同一个时间点,也可以是在同一个时间段,例如,第一线程、第二线程都在15:00发起的请求,这就是同一个时间点,第一线程在15:00发起的请求,第二线程在15:02发起的请求,但是第一线程在15:02并没有完成获取业务数据,这就是同一个时间段。第二线程可以是单一线程,也可以是多个线程。
在一些实施例中,可以是多个线程并发获取同一业务数据,多个线程包括第一线程、第二线程和其它线程,其它线程的处理方式与第二线程的处理方式相同。
步骤S102、在缓存分片集合中查找所述业务数据。
第一线程、第二线程请求获取业务数据,先在缓存分片集合中查找,如果没有查找到,再到后端查找对应的业务数据。缓存分片集合是包括多个缓存分片的一个集合,多个缓存分片是分布式布置。
步骤S103、若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据。
如果在缓存分片集合没有查找到业务数据,此时,不能将第一线程、第二线程都从后端请求业务数据,让第一线程、第二线程竞争一把锁,允许竞争到锁的线程从后端请求业务数据,并对后端的业务数据进行加锁,不允许其它的线程从后端请求业务数据,也就是,未竞争到锁的线程不能后端请求业务数据。
步骤S104、识别所述第一线程、所述第二线程是否存在一个线程加锁成功。
识别后端的业务数据是否锁定,如果识别出后端的业务数据锁定,再识别出是第一线程,还是第二线程对后端的业务数据的加锁,对后端的业务数据的加锁的线程具有锁标识,通过识别出锁标识,从而判断出是第一线程,还是第二线程对后端的业务数据的加锁。
步骤S105、若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态。
如果第一线程、第二线程中任一个线程加锁成功,另一个线程需要调整为等状态,就是不让该线程从后端请求业务数据。具体地,如果第一线程加锁成功,那么第二线程调整为等待状态,如果第二线程加锁成功,那么第一线程调整为等待状态。
步骤S106、通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳。
第一线程通过后端获取业务数据,为了使第二线程能够从缓存分片集合中获取业务数据,需要将后端的业务数据写入到缓存分片集合中,并记录后端的业务数据的时间,获取当前时间,得到第一时间戳。
步骤S107、通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片。
对缓存分片集合中每一个缓存分片是设置一个分片id,每一个时间戳通过Hash算法都会计算出一个分片id,从而在缓存分片集合中查找到对应的缓存分片。
步骤S108、将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定。
在第一时间戳和第一目标业务数据写入第一缓存分片之后,第一线程的加锁已经结束,解除对后端的业务数据的锁定,允许其它线程对后端的业务数据的请求获取。
步骤S109、解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳。
解除第二线程的等待状态,第二线程再次在在缓存分片集合中查找业务数据,此时,缓存分片集合存储有业务数据,第二线程在第一缓存分片中查找到业务数据,也就是第一目标业务数据,从第一缓存分片中获取第一目标业务数据。后端的业务数据可能会存在更新的情况,需要从后端的获取业务数据,此时新增一个线程获取后端的业务数据,以及此时业务数据对应的时间戳。
步骤S110、通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片。
步骤S111、将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
通过Hash算法计算出对应的缓存分片,之后将第二时间戳和第二目标业务数据写入对应的缓存分片中,对应的缓存分片即是第二缓存分片,这样,后续的线程不仅可以在缓存分片集合获取到业务数据,还能获取到可能更新后的业务数据。
在本实施例中,在步骤S111之后,包括:
接收第三线程获取所述业务数据的请求;
在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
第三线程是在第一线程、第二线程请求业务数据线束之后发起获取业务数据的请求。此时,缓存分片集合中有两个缓存分片存储有业务数据,第三线程是从第一缓存分片中获取业务数据,还是从第二缓存分片中获取业务数据,是根据第一缓存分片中的第一时间戳与第二缓存分片中的第二时间戳的哪一个时间戳的时间是最新的。第二缓存分片的业务数据即是第二目标业务数据,在第三线程从第二缓存分片中获取第二目标业务数据之后,还需要从后端获取业务数据,以及对应的时间戳,然后,将此时的业务数据和对应的时间戳写入对应的缓存分片中,以便后续的线程不仅可以在缓存分片集合获取到业务数据,还能获取到可能更新后的业务数据。
在一些实施例中,在步骤S111之后,包括:
接收第四线程获取所述业务数据的请求;
在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程,获取后端的业务数据的最后修改时间;
将所述最后修改时间与所述第二时间戳的时间进行比较;
若所述最后修改时间是最新的时间,则获取后端的业务数据,获得第六目标业务数据,并获取当前时间,获得第六时间戳;
通过所述Hash算法计算出所述第六时间戳在所述缓存分片集合中对应的缓存分片,获得第六缓存分片;
将所述第六时间戳和所述第六目标业务数据写入所述第三缓存分片;
若所述第二时间戳是最新的时间,则不获取后端的业务数据写入对应的缓存分片中。
第四线程是在第一线程、第二线程请求业务数据线束之后发起获取业务数据的请求。此时,缓存分片集合中有两个缓存分片存储有业务数据,第四线程是从第一缓存分片中获取业务数据,还是从第二缓存分片中获取业务数据,是根据第一缓存分片中的第一时间戳与第二缓存分片中的第二时间戳的哪一个时间戳的时间是最新的。在第四线程获取到业务数据之后,不是直接从后端获取业务数据,而是先从后端获取业务数据的最后修改时间,通过最后修改时间与第二时间戳的时间比较,如果最后修改时间是最新的,说明后端的业务数据进行了更新,那么需要从后端获取业务数据,如果第二时间戳的时间是最新的,说明后端的业务数据没有进行更新,那么不需要从后端获取业务数据,减少从后端获取业务数据的次数,以及减少将业务数据写入缓存分片集合的次数。
在本实施例中,在步骤S102之后,包括:
若查找到所述业务数据,则查找所述业务数据所在的缓存分片;
若所述业务数据所在的缓存分片为一个缓存分片,则将所述一个缓存分片中的业务数据返给所述第一线程、所述第二线程;
获取后端的业务数据,获得第四目标业务数据,并获取当前时间,获得第四时间戳;
通过所述Hash算法计算出所述第四时间戳在所述缓存分片集合中对应的缓存分片,获得第四缓存分片;
将所述第四时间戳和所述第四目标业务数据写入所述第四缓存分片。
如果缓存分片集合中存储有业务数据,并且只有一个缓存分片存储有业务数据,那么从缓存分片集中对应的缓存分片中获取业务数据返给第一线程、第二线程,而不需要从后端获取业务数据返给第一线程、第二线程。之后还需要从后端获取业务数据,以及对应的时间戳,然后,将此时的业务数据和对应的时间戳写入对应的缓存分片中。
在所述若查找到所述业务数据,则查找所述业务数据所在的缓存分片的步骤之后,包括:
若所述业务数据所在的缓存分片为多个缓存分片,则从所述多个缓存分片中获取对应的时间戳;
比较多个时间戳,通过比较结果判定所述多个时间戳中的一个时间戳的时间为最新,获得目标时间戳;
将所述目标时间戳对应的缓存分片中的业务数据返给所述第一线程、所述第二线程;
获取后端的业务数据,获得第五目标业务数据,并获取当前时间,获得第五时间戳;
通过所述Hash算法计算出所述第五时间戳在所述缓存分片集合中对应的缓存分片,获得第五缓存分片;
将所述第五时间戳和所述第五目标业务数据写入所述第五缓存分片。
如果多个缓存分片存储有业务数据,那么需要对多个缓存分片上的时间戳进行比较,将时间戳是最新的一个缓存分片上的业务数据返给第一线程、第二线程。之后还需要从后端获取业务数据,以及对应的时间戳,然后,将此时的业务数据和对应的时间戳写入对应的缓存分片中。
在本实施例中,在所述解除所述第二线程的等待状态的步骤之前,包括:
检测所述第一缓存分片是否存在数据写入;
若存在数据写入,则再检测所述数据写入是否结束;
若结束,则生成解除所述第二线程的等待状态的指令。
通过检测第一缓存分片写入数据结束,生成解除指令,执行该指令,解除第二线程的等待状态。
在一些实施例中,在所述将所述第二线程调整为等待状态的步骤之后,在所述解除所述第二线程的等待状态的步骤之前,包括:
添加时间锁给所述第二线程;
在所述解除所述第二线程的等待状态的步骤之前,包括:
判断所述时间锁是否失效;
若所述时间锁失效,则生成解除所述第二线程的等待状态的指令。
给第二线程添加时间锁,当时间锁失效时,生成解除指令,执行该指令,解除第二线程的等待状态。
综上所述,第一线程和第二线程并发对同一业务数据进行请求获取,如果在缓存分片集合没有查找业务数据,那么让第一线程和第二线程竞争锁,从后端的业务数据进行获取,如果第一线程竞争成功,对后端的业务数据进行加锁,只允许第一线程对业务数据获取,在第一线程获取到业务数据,并将对应的第一目标业务数据、第一时间戳写入对应的第一缓存分片,之后对后端的业务数据进行解锁,第二线程从第一缓存分片中获取第一目标业务数据,之后将对应的第二目标业务数据、第二时间戳写入对应的第二缓存分片,解决服务器的链接太多,占用资源过多,使得存储效率下降,进而导致服务器宕机的问题。
如图2所示,本申请实施例提出一种数据的缓存装置1,装置1包括接收模块11、查找模块12、加锁模块13、识别模块14、调整模块15、第一获取模块16、第一计算模块17、第一写入模块18、第二获取模块19、第二计算模块20和第二写入模块21。
接收模块11,用于接收第一线程、第二线程并发获取同一业务数据的请求。
查找模块12,用于在缓存分片集合中查找所述业务数据。
加锁模块13,用于若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据。
识别模块14,用于识别所述第一线程、所述第二线程是否存在一个线程加锁成功。
调整模块15,用于若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态。
第一获取模块16,用于通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳。
第一计算模块17,用于通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片。
第一写入模块18,用于将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定。
第二获取模块19,用于解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳。
第二计算模块20,用于通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片。
第二写入模块21,用于将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
在本实施例中,装置1包括:
第一接收模块,用于接收第三线程获取所述业务数据的请求;
第一查找模块,用于在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
第三获取模块,用于从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
第一比较模块,用于比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
第一发送模块,用于将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
第四获取模块,用于获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
第三计算模块,用于通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
第三写入模块,用于将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
在一些实施例中,装置1包括:
第二接收模块,用于接收第四线程获取所述业务数据的请求,
第二查找模块,用于在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
第四获取模块,用于从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
第二比较模块,用于比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
第五获取模块,用于将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程,获取后端的业务数据的最后修改时间;
第三比较模块,用于将所述最后修改时间与所述第二时间戳的时间进行比较;
第六获取模块,用于若所述最后修改时间是最新的时间,则获取后端的业务数据,获得第六目标业务数据,并获取当前时间,获得第六时间戳;
第四计算模块,用于通过所述Hash算法计算出所述第六时间戳在所述缓存分片集合中对应的缓存分片,获得第六缓存分片;
第四写入模块,用于将所述第六时间戳和所述第六目标业务数据写入所述第三缓存分片;
第一拒绝模块,用于若所述第二时间戳是最新的时间,则不获取后端的业务数据写入对应的缓存分片中。
在本实施例中,装置1包括:
第三查找模块,用于若查找到所述业务数据,则查找所述业务数据所在的缓存分片;
第二发送模块,用于若所述业务数据所在的缓存分片为一个缓存分片,则将所述一个缓存分片中的业务数据返给所述第一线程、所述第二线程;
第七获取模块,用于获取后端的业务数据,获得第四目标业务数据,并获取当前时间,获得第四时间戳;
第五计算模块,用于通过所述Hash算法计算出所述第四时间戳在所述缓存分片集合中对应的缓存分片,获得第四缓存分片;
第五写入模块,用于将所述第四时间戳和所述第四目标业务数据写入所述第四缓存分片。
装置1包括:
第八获取模块,用于若所述业务数据所在的缓存分片为多个缓存分片,则从所述多个缓存分片中获取对应的时间戳;
第四比较模块,用于比较多个时间戳,通过比较结果判定所述多个时间戳中的一个时间戳的时间为最新,获得目标时间戳;
第三发送模块,用于将所述目标时间戳对应的缓存分片中的业务数据返给所述第一线程、所述第二线程;
第九获取模块,用于获取后端的业务数据,获得第五目标业务数据,并获取当前时间,获得第五时间戳;
第六计算模块,用于通过所述Hash算法计算出所述第五时间戳在所述缓存分片集合中对应的缓存分片,获得第五缓存分片;
第六写入模块,用于将所述第五时间戳和所述第五目标业务数据写入所述第五缓存分片。
在本实施例中,装置1包括:
第一检测模块,用于检测所述第一缓存分片是否存在数据写入;
第二检测模块,用于若存在数据写入,则再检测所述数据写入是否结束;
第一生成模块,用于若结束,则生成解除所述第二线程的等待状态的指令。
在一些实施例中,装置1包括:
第一添加模块,用于添加时间锁给所述第二线程。
装置1包括:
第一判断模块,用于判断所述时间锁是否失效;
第二生成模块,用于若所述时间锁失效,则生成解除所述第二线程的等待状态的指令。
如图3所示,本申请实施例中还提供一种计算机设备,该计算机设备可以是服务器,其内部结构可以如图3所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设计的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储数据的缓存方法的模型等数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种数据的缓存方法。
本申请一实施例还提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现一种数据的缓存方法。所述计算机可读存储介质,例如为非易失性的计算机可读存储介质,或者为易失性的计算机可读存储介质。

Claims (20)

  1. 一种数据的缓存方法,其特征在于,所述方法包括:
    接收第一线程、第二线程并发获取同一业务数据的请求;
    在缓存分片集合中查找所述业务数据;
    若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
    识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
    若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
    通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳;
    通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
    将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
    解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
    通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
    将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
  2. 根据权利要求1所述的数据的缓存方法,其特征在于,在所述将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片的步骤之后,包括:
    接收第三线程获取所述业务数据的请求;
    在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
    获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
    通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
    将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
  3. 根据权利要求1所述的数据的缓存方法,其特征在于,在所述将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片的步骤之后,包括:
    接收第四线程获取所述业务数据的请求;
    在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    将所述第二缓存分片中的所述第二目标业务数据返给所述第四线程,获取后端的业务数据的最后修改时间;
    将所述最后修改时间与所述第二时间戳的时间进行比较;
    若所述最后修改时间是最新的时间,则获取后端的业务数据,获得第六目标业务数据,并获取当前时间,获得第六时间戳;
    通过所述Hash算法计算出所述第六时间戳在所述缓存分片集合中对应的缓存分片,获得第六缓存分片;
    将所述第六时间戳和所述第六目标业务数据写入所述第三缓存分片;
    若所述第二时间戳是最新的时间,则不获取后端的业务数据写入对应的缓存分片中。
  4. 根据权利要求1所述的数据的缓存方法,其特征在于,在所述在缓存分片集合中查找所述业务数据的步骤之后,包括:
    若查找到所述业务数据,则查找所述业务数据所在的缓存分片;
    若所述业务数据所在的缓存分片为一个缓存分片,则将所述一个缓存分片中的业务数据返给所述第一线程、所述第二线程;
    获取后端的业务数据,获得第四目标业务数据,并获取当前时间,获得第四时间戳;
    通过所述Hash算法计算出所述第四时间戳在所述缓存分片集合中对应的缓存分片,获得第四缓存分片;
    将所述第四时间戳和所述第四目标业务数据写入所述第四缓存分片。
  5. 根据权利要求4所述的数据的缓存方法,其特征在于,在所述若查找到所述业务数据,则查找所述业务数据所在的缓存分片的步骤之后,包括:
    若所述业务数据所在的缓存分片为多个缓存分片,则从所述多个缓存分片中获取对应的时间戳;
    比较多个时间戳,通过比较结果判定所述多个时间戳中的一个时间戳的时间为最新,获得目标时间戳;
    将所述目标时间戳对应的缓存分片中的业务数据返给所述第一线程、所述第二线程;
    获取后端的业务数据,获得第五目标业务数据,并获取当前时间,获得第五时间戳;
    通过所述Hash算法计算出所述第五时间戳在所述缓存分片集合中对应的缓存分片,获得第五缓存分片;
    将所述第五时间戳和所述第五目标业务数据写入所述第五缓存分片。
  6. 根据权利要求1所述的数据的缓存方法,其特征在于,在所述解除所述第二线程的等待状态的步骤之前,包括:
    检测所述第一缓存分片是否存在数据写入;
    若存在数据写入,则再检测所述数据写入是否结束;
    若结束,则生成解除所述第二线程的等待状态的指令。
  7. 根据权利要求1所述的数据的缓存方法,其特征在于,在所述将所述第二线程调整为等待状态的步骤之后,在所述解除所述第二线程的等待状态的步骤之前,包括:
    添加时间锁给所述第二线程;
    在所述解除所述第二线程的等待状态的步骤之前,包括:
    判断所述时间锁是否失效;
    若所述时间锁失效,则生成解除所述第二线程的等待状态的指令。
  8. 一种数据的缓存装置,其特征在于,所述装置包括:
    接收模块,用于接收第一线程、第二线程并发获取同一业务数据的请求;
    查找模块,用于在缓存分片集合中查找所述业务数据;
    加锁模块,用于若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
    识别模块,用于识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
    调整模块,用于若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
    第一获取模块,用于通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳;
    第一计算模块,用于通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
    第一写入模块,用于将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
    第二获取模块,用于解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
    第二计算模块,用于通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
    第二写入模块,用于将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
  9. 根据权利要求8所述的数据的缓存装置,其特征在于,所述装置包括:
    第一接收模块,用于接收第三线程获取所述业务数据的请求;
    第一查找模块,用于在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    第三获取模块,用于从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    第一比较模块,用于比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    第一发送模块,用于将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
    第四获取模块,用于获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
    第三计算模块,用于通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
    第三写入模块,用于将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
  10. 根据权利要求8所述的数据的缓存装置,其特征在于,所述装置包括:
    第二接收模块,用于接收第四线程获取所述业务数据的请求;
    第二查找模块,用于在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    第四获取模块,用于从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    第二比较模块,用于比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    第五获取模块,用于将所述第二缓存分片中的所述第二目标业务数据返给所述第四线程,获取后端的业务数据的最后修改时间;
    第三比较模块,用于将所述最后修改时间与所述第二时间戳的时间进行比较;
    第六获取模块,用于若所述最后修改时间是最新的时间,则获取后端的业务数据,获得第六目标业务数据,并获取当前时间,获得第六时间戳;
    第四计算模块,用于通过所述Hash算法计算出所述第六时间戳在所述缓存分片集合中对应的缓存分片,获得第六缓存分片;
    第四写入模块,用于将所述第六时间戳和所述第六目标业务数据写入所述第三缓存分片;
    第一拒绝模块,用于若所述第二时间戳是最新的时间,则不获取后端的业务数据写入对应的缓存分片中。
  11. 根据权利要求8所述的数据的缓存装置,其特征在于,所述装置包括:
    第三查找模块,用于若查找到所述业务数据,则查找所述业务数据所在的缓存分片;
    第二发送模块,用于若所述业务数据所在的缓存分片为一个缓存分片,则将所述一个缓存分片中的业务数据返给所述第一线程、所述第二线程;
    第七获取模块,用于获取后端的业务数据,获得第四目标业务数据,并获取当前时间,获得第四时间戳;
    第五计算模块,用于通过所述Hash算法计算出所述第四时间戳在所述缓存分片集合中对应的缓存分片,获得第四缓存分片;
    第五写入模块,用于将所述第四时间戳和所述第四目标业务数据写入所述第四缓存分片。
  12. 根据权利要求11所述的数据的缓存装置,其特征在于,所述装置包括:
    第八获取模块,用于若所述业务数据所在的缓存分片为多个缓存分片,则从所述多个缓存分片中获取对应的时间戳;
    第四比较模块,用于比较多个时间戳,通过比较结果判定所述多个时间戳中的一个时间戳的时间为最新,获得目标时间戳;
    第三发送模块,用于将所述目标时间戳对应的缓存分片中的业务数据返给所述第一线程、所述第二线程;
    第九获取模块,用于获取后端的业务数据,获得第五目标业务数据,并获取当前时间,获得第五时间戳;
    第六计算模块,用于通过所述Hash算法计算出所述第五时间戳在所述缓存分片集合中对应的缓存分片,获得第五缓存分片;
    第六写入模块,用于将所述第五时间戳和所述第五目标业务数据写入所述第五缓存分片。
  13. 根据权利要求8所述的数据的缓存装置,其特征在于,所述装置包括:
    第一检测模块,用于检测所述第一缓存分片是否存在数据写入;
    第二检测模块,用于若存在数据写入,则再检测所述数据写入是否结束;
    第一生成模块,用于若结束,则生成解除所述第二线程的等待状态的指令。
  14. 根据权利要求8所述的数据的缓存装置,其特征在于,所述装置包括:
    第一添加模块,用于添加时间锁给所述第二线程;
    第一判断模块,用于判断所述时间锁是否失效;
    第二生成模块,用于若所述时间锁失效,则生成解除所述第二线程的等待状态的指令。
  15. 一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,其特征在于,所述处理器执行所述计算机程序时实现数据的缓存方法,所述方法包括:
    接收第一线程、第二线程并发获取同一业务数据的请求;
    在缓存分片集合中查找所述业务数据;
    若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
    识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
    若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
    通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳;
    通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
    将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
    解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
    通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
    将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
  16. 根据权利要求15所述的计算机设备,其特征在于,在所述将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片的步骤之后,包括:
    接收第三线程获取所述业务数据的请求;
    在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
    获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
    通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
    将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
  17. 根据权利要求15所述的计算机设备,其特征在于,在所述将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片的步骤之后,包括:
    接收第四线程获取所述业务数据的请求;
    在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    将所述第二缓存分片中的所述第二目标业务数据返给所述第四线程,获取后端的业务数据的最后修改时间;
    将所述最后修改时间与所述第二时间戳的时间进行比较;
    若所述最后修改时间是最新的时间,则获取后端的业务数据,获得第六目标业务数据,并获取当前时间,获得第六时间戳;
    通过所述Hash算法计算出所述第六时间戳在所述缓存分片集合中对应的缓存分片,获得第六缓存分片;
    将所述第六时间戳和所述第六目标业务数据写入所述第三缓存分片;
    若所述第二时间戳是最新的时间,则不获取后端的业务数据写入对应的缓存分片中。
  18. 根据权利要求15所述的计算机设备,其特征在于,在所述在缓存分片集合中查找所述业务数据的步骤之后,包括:
    若查找到所述业务数据,则查找所述业务数据所在的缓存分片;
    若所述业务数据所在的缓存分片为一个缓存分片,则将所述一个缓存分片中的业务数据返给所述第一线程、所述第二线程;
    获取后端的业务数据,获得第四目标业务数据,并获取当前时间,获得第四时间戳;
    通过所述Hash算法计算出所述第四时间戳在所述缓存分片集合中对应的缓存分片,获得第四缓存分片;
    将所述第四时间戳和所述第四目标业务数据写入所述第四缓存分片。
  19. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现数据的缓存方法,所述方法包括:
    接收第一线程、第二线程并发获取同一业务数据的请求;
    在缓存分片集合中查找所述业务数据;
    若未查找到所述业务数据,则对后端的业务数据进行锁定,将所述第一线程、所述第二线程竞争加锁,其中加锁成功的线程允许获取后端的业务数据;
    识别所述第一线程、所述第二线程是否存在一个线程加锁成功;
    若识别出所述第一线程加锁成功,则将所述第二线程调整为等待状态;
    通过所述第一线程获取后端的业务数据,获得第一目标业务数据,并获取当前时间,获得第一时间戳;
    通过Hash算法计算出所述第一时间戳在所述缓存分片集合中对应的缓存分片,获得第一缓存分片;
    将所述第一时间戳和所述第一目标业务数据写入所述第一缓存分片,解除对后端的业务数据的锁定;
    解除所述第二线程的等待状态,将在所述第一缓存分片中的所述第一目标业务数据返给所述第二线程,以及获取后端的业务数据,获得第二目标业务数据,并获取当前时间,获得第二时间戳;
    通过所述Hash算法计算出所述第二时间戳在所述缓存分片集合中对应的缓存分片,获得第二缓存分片;
    将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片。
  20. 根据权利要求19所述的计算机可读存储介质,其特征在于,在所述将所述第二时间戳和所述第二目标业务数据写入所述第二缓存分片的步骤之后,包括:
    接收第三线程获取所述业务数据的请求;
    在缓存分片集合中查找所述业务数据,查找到所述业务数据所在的缓存分片为所述第一缓存分片和所述第二缓存分片;
    从所述第一缓存分片中获取所述第一时间戳,从所述第二缓存分片中获取所述第二时间戳;
    比较所述第一时间戳与所述第二时间戳,通过比较结果判定所述第二时间戳的时间为最新;
    将所述第二缓存分片中的所述第二目标业务数据返给所述第三线程;
    获取后端的业务数据,获得第三目标业务数据,并获取当前时间,获得第三时间戳;
    通过所述Hash算法计算出所述第三时间戳在所述缓存分片集合中对应的缓存分片,获得第三缓存分片;
    将所述第三时间戳和所述第三目标业务数据写入所述第三缓存分片。
PCT/CN2019/119216 2019-04-16 2019-11-18 数据的缓存方法、装置、计算机设备 WO2020211372A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910305832.7A CN110147386A (zh) 2019-04-16 2019-04-16 数据的缓存方法、装置、计算机设备
CN201910305832.7 2019-04-16

Publications (1)

Publication Number Publication Date
WO2020211372A1 true WO2020211372A1 (zh) 2020-10-22

Family

ID=67589807

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/119216 WO2020211372A1 (zh) 2019-04-16 2019-11-18 数据的缓存方法、装置、计算机设备

Country Status (2)

Country Link
CN (1) CN110147386A (zh)
WO (1) WO2020211372A1 (zh)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110147386A (zh) * 2019-04-16 2019-08-20 平安科技(深圳)有限公司 数据的缓存方法、装置、计算机设备
CN110941449A (zh) * 2019-11-15 2020-03-31 新华三半导体技术有限公司 Cache块处理方法、装置及处理器芯片
CN113301101B (zh) * 2021-02-01 2022-08-16 淘宝(中国)软件有限公司 分布式文件系统的数据传输方法以及装置
CN115002219B (zh) * 2022-05-30 2023-07-25 广州市百果园网络科技有限公司 服务调用方法、装置、设备、系统、存储介质及产品

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160085679A1 (en) * 2009-11-30 2016-03-24 International Business Machines Corporation Managing Access to a Cache Memory
CN105488208A (zh) * 2015-12-11 2016-04-13 北京奇虎科技有限公司 数据查找方法与装置
CN106844784A (zh) * 2017-03-14 2017-06-13 上海网易小额贷款有限公司 数据缓存方法、装置及计算机可读存储介质
US20180217759A1 (en) * 2016-06-06 2018-08-02 International Business Machines Corporation Invoking input/output (i/o) threads on processors to demote tracks from a cache
CN108874552A (zh) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 分布式锁执行方法、装置及系统、应用服务器和存储介质
CN110147386A (zh) * 2019-04-16 2019-08-20 平安科技(深圳)有限公司 数据的缓存方法、装置、计算机设备

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8296394B1 (en) * 2007-04-10 2012-10-23 AT & T Intellectual Property II, LP Method and system for caching real-time data
CN102508854A (zh) * 2011-09-29 2012-06-20 畅捷通信息技术股份有限公司 数据访问装置和方法
CN108090058B (zh) * 2016-11-21 2021-10-29 广东亿迅科技有限公司 一种高并发活动交互方法
CN109491928B (zh) * 2018-11-05 2021-08-10 深圳乐信软件技术有限公司 缓存控制方法、装置、终端及存储介质

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160085679A1 (en) * 2009-11-30 2016-03-24 International Business Machines Corporation Managing Access to a Cache Memory
CN105488208A (zh) * 2015-12-11 2016-04-13 北京奇虎科技有限公司 数据查找方法与装置
US20180217759A1 (en) * 2016-06-06 2018-08-02 International Business Machines Corporation Invoking input/output (i/o) threads on processors to demote tracks from a cache
CN106844784A (zh) * 2017-03-14 2017-06-13 上海网易小额贷款有限公司 数据缓存方法、装置及计算机可读存储介质
CN108874552A (zh) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 分布式锁执行方法、装置及系统、应用服务器和存储介质
CN110147386A (zh) * 2019-04-16 2019-08-20 平安科技(深圳)有限公司 数据的缓存方法、装置、计算机设备

Also Published As

Publication number Publication date
CN110147386A (zh) 2019-08-20

Similar Documents

Publication Publication Date Title
WO2020211372A1 (zh) 数据的缓存方法、装置、计算机设备
US10860612B2 (en) Parallel replication across formats
CN110502507B (zh) 一种分布式数据库的管理系统、方法、设备和存储介质
JP4794571B2 (ja) データベースに対するアクセスを効率化するシステム、および、その方法
US9071602B2 (en) Biometric authentication system and biometric authentication method
US10402285B2 (en) Hybrid database concurrent transaction control
JP7098007B2 (ja) データベースのための遠隔データ同期方法及び装置
CN102779132B (zh) 数据更新方法、系统及数据库服务器
US11899689B2 (en) Blockchain-based data synchronization method, apparatus, and computer-readable storage medium
CN111190935B (zh) 数据读取方法、装置、计算机设备及存储介质
US20230106118A1 (en) Distributed processing of transactions in a network using timestamps
US11550646B2 (en) Method of verifying access of multi-core interconnect to level-2 cache
WO2019024780A1 (zh) 区块链轻量化处理方法、区块链节点及存储介质
US9170837B2 (en) Transaction concurrent execution control system, method and program for carrying out a control of concurrently executing a transaction, including measuring execution time from starting to ending of transaction execution
CN112307119A (zh) 数据同步方法、装置、设备及存储介质
CN111339200A (zh) 一种基于数据库同步的数据校验方法及数据校验系统
US20150074070A1 (en) System and method for reconciling transactional and non-transactional operations in key-value stores
CN109213828B (zh) 区块生成方法、装置、设备及存储介质
JP2023541298A (ja) トランザクション処理方法、システム、装置、機器、及びプログラム
CN113056734B (zh) 管理共享数据库的系统和方法
CN112988777B (zh) 对象处理方法、装置、计算机设备和存储介质
WO2020042852A1 (zh) 用于复制数据的方法、主设备以及从设备
CN108460047B (zh) 数据同步方法及设备
CN112866339B (zh) 数据传输方法、装置、计算机设备和存储介质
CN115982279A (zh) 数据同步方法、装置、系统和计算机设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19925091

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19925091

Country of ref document: EP

Kind code of ref document: A1