Caching method, device, equipment and storage medium based on double cache areas

文档序号:1296041 发布日期:2020-08-07 浏览:4次 中文

阅读说明:本技术 基于双缓存区的缓存方法、装置、设备及存储介质 (Caching method, device, equipment and storage medium based on double cache areas ) 是由 艾可德 于 2020-03-24 设计创作,主要内容包括:本发明涉及云技术领域,公开了一种基于双缓存区的缓存方法、装置、设备及存储介质,用于利用线程共享的缓存方式与线程隔离的缓存方式缓存数据,提高了数据缓存的灵活性。基于双缓存区的缓存方法包括:获取目标终端的缓存请求;判断缓存请求是否属于写入缓存请求、读取缓存请求或者删除缓存请求;若缓存请求属于写入缓存请求,采用线程共享写入方式或者线程隔离写入方式,将写入映射结构缓存实体写入预置缓存区;若缓存请求属于读取缓存请求,则采用线程共享读取方式或者线程隔离读取方式从预置缓存区中获取目标预置映射结构缓存实体;若缓存请求属于删除缓存请求,则采用线程共享删除方式或者线程隔离删除方式删除预置待删除缓存请求实体。(The invention relates to the technical field of cloud, and discloses a caching method, a caching device, caching equipment and a caching medium based on double cache areas, which are used for caching data by utilizing a thread sharing caching mode and a thread isolating caching mode, so that the flexibility of data caching is improved. The caching method based on the double caching areas comprises the following steps: obtaining a cache request of a target terminal; judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request; if the cache request belongs to a write-in cache request, writing a write-in mapping structure cache entity into a preset cache region by adopting a thread sharing write-in mode or a thread isolation write-in mode; if the cache request belongs to a read cache request, acquiring a target preset mapping structure cache entity from a preset cache region by adopting a thread sharing read mode or a thread isolation read mode; and if the cache request belongs to a cache deletion request, deleting the preset cache request entity to be deleted by adopting a thread sharing deletion mode or a thread isolation deletion mode.)

1. A cache method based on double cache regions is characterized in that the cache method based on double cache regions comprises the following steps:

obtaining a cache request of a target terminal;

judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request;

if the cache request belongs to the write-in cache request, obtaining a write-in mapping structure cache entity, and writing the write-in mapping structure cache entity into a preset cache region by adopting a thread sharing write-in mode or a thread isolation write-in mode, wherein the preset cache region comprises a preset thread sharing cache region and a preset thread isolation cache region;

if the cache request belongs to the read cache request, acquiring a target preset mapping structure cache entity and reading the target preset mapping structure cache entity from a preset cache region by adopting a thread sharing read mode or a thread isolation read mode, wherein the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity acquired from the preset thread sharing cache region by adopting the thread sharing read mode, and the second target preset mapping structure cache entity is a preset mapping structure cache entity acquired from the preset thread isolation cache region by adopting the thread isolation read mode;

if the cache request belongs to the cache deletion request, acquiring a plurality of preset cache entities to be deleted in a preset cache region by adopting a thread sharing deletion mode or a thread isolation deletion mode, and deleting the plurality of preset cache entities to be deleted, wherein the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in the preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in the preset thread isolation cache region.

2. The double-buffer-area-based caching method according to claim 1, wherein if the cache request belongs to the write cache request, obtaining a write mapping structure cache entity, and writing the write mapping structure cache entity into a preset cache area in a thread-sharing write manner or a thread-isolation write manner, where the preset cache area includes a preset thread-sharing cache area and a preset thread-isolation cache area, the method includes:

if the cache request belongs to the write-in cache request, judging whether a preset cache region exists, if not, establishing a preset thread isolation cache region, and then establishing a preset thread sharing cache region to obtain a preset cache region;

acquiring an initial write mapping structure cache entity according to the write cache request, and determining a write logic type according to the initial write mapping structure cache entity;

judging whether the writing mode of the writing cache request is a thread sharing writing mode or a thread isolation writing mode according to the writing logic type;

if the writing mode of the writing cache request is judged to be a thread sharing writing mode, adjusting the state of the preset thread sharing cache region to be a temporary reading and writing state, adjusting the initial writing mapping structure cache entity to obtain a writing mapping structure cache entity, and writing the writing mapping structure cache entity into the preset thread sharing cache region;

and if the writing mode of the writing cache request is judged to be a thread isolation writing mode, adjusting the initial writing mapping structure cache entity to obtain a writing mapping structure cache entity, and writing the writing mapping structure cache entity into a preset thread isolation cache region.

3. The dual-cache-region-based caching method of claim 2, wherein said obtaining an initial write mapping structure cache entity according to the write cache request, and determining a write logic type according to the initial write mapping structure cache entity comprises:

determining a cache handle according to the write-in cache request, and matching a corresponding first mapping structure cache entity according to the cache handle;

adding a key value into the first mapping structure cache entity to generate a second mapping structure cache entity, wherein the key value is used for storing the content value of the first mapping structure cache entity;

adding effective duration in the second mapping structure cache entity to generate a third mapping structure cache entity;

adding an updating time into the third mapping structure cache entity to generate an initial writing mapping structure cache entity, and determining a writing logic type according to the initial writing mapping structure cache entity, wherein the effective duration and the updating time are used for judging whether the initial writing mapping structure is overtime and invalid.

4. The dual-cache-region-based caching method of claim 2, wherein if it is determined that the write mode of the write cache request is a thread isolation write mode, adjusting the initial write mapping structure cache entity to obtain a write mapping structure cache entity, and writing the write mapping structure cache entity into a preset thread isolation cache region comprises:

if the writing mode of the writing cache request is judged to be a thread isolation writing mode, matching the initial writing mapping structure cache entity with a plurality of preset writing threads in the preset thread isolation cache region to obtain a target writing thread;

judging whether the target write-in thread has a corresponding write-in sub-cache region in the preset thread isolation cache region;

if the write-in sub-cache region corresponding to the target write-in thread does not exist in the preset thread isolation cache region, establishing a write-in sub-cache region corresponding to the target write-in thread to obtain a target write-in sub-cache region;

and adjusting the updating time of the initial write mapping structure cache entity to be the current time to obtain a write mapping structure cache entity, and storing the write mapping structure cache entity into the target write sub-cache region, wherein the target write sub-cache region is arranged in the preset thread isolation cache region.

5. The dual-cache-region-based caching method of claim 1, wherein if said cache request belongs to said read cache request, obtaining a target preset mapping structure cache entity from a preset cache region by adopting a thread sharing reading mode or a thread isolation reading mode and reading the target preset mapping structure cache entity, the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity acquired from a preset thread shared cache region in a thread sharing reading mode, the second target preset mapping structure cache entity is a preset mapping structure cache entity acquired from a preset thread isolation cache region in a thread isolation reading mode and comprises:

if the cache request belongs to the read cache request, extracting a read handle based on the cache request;

determining a read logic type based on the read handle, and judging whether a read mode of the read cache request is a thread sharing read mode or a thread isolation read mode based on the read logic type;

if the reading mode of the reading cache request is the thread sharing reading mode, adjusting the state of the preset thread sharing cache area to be a temporary reading-writing state, acquiring a first target preset mapping structure cache entity from the preset thread sharing cache area, and reading the first target preset mapping structure cache entity;

and if the reading mode of the reading cache request is the thread isolation reading mode, acquiring a second target preset mapping structure cache entity from the preset thread isolation cache region, and reading the second target preset mapping structure cache entity.

6. The dual-cache-area-based caching method of claim 5, wherein if the read mode of the read cache request is the thread isolation read mode, acquiring a second target preset mapping structure cache entity from the preset thread isolation cache area, and reading the second target preset mapping structure cache entity comprises:

if the reading mode of the reading cache request is the thread isolation reading mode, determining a target reading thread in a plurality of preset reading threads of the preset thread isolation cache region;

extracting a target reading sub-thread according to the target reading thread, and reading a second target preset mapping structure cache entity from the target reading sub-thread;

acquiring a preset effective duration, a preset updating moment and a current moment of a cache entity of the second target preset mapping structure, summing the preset effective duration and the preset updating moment to obtain a failure moment, and judging whether the current moment is greater than the failure moment;

and if the current time is greater than the failure time, setting the second target preset mapping structure cache entity as a null value.

7. The double-cache-region-based caching method according to any one of claims 1 to 6, wherein if the cache request of the target terminal belongs to the cache deletion request, acquiring a plurality of preset cache entities to be deleted in a preset cache region and deleting the plurality of preset cache entities to be deleted in a thread sharing deletion manner or a thread isolation deletion manner, where the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in a preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in a preset thread isolation cache region, the method includes:

if the cache request belongs to the cache deletion request and a thread sharing deletion mode is adopted to delete a preset cache request entity to be deleted, the state of a preset thread sharing cache area is adjusted to be a temporary read-write state, and a plurality of preset cache entities in the preset thread sharing cache area are traversed based on the updating time, the effective duration and the current time, a plurality of first preset cache entities to be deleted are determined, and the first preset cache entities to be deleted are deleted;

if the cache request belongs to the cache deletion request and a thread isolation deletion mode is adopted to delete a preset cache request entity to be deleted, traversing a plurality of sub-cache regions in the preset thread isolation cache region, determining a second preset cache entity to be deleted in the plurality of sub-cache regions based on the updating time, the effective duration and the current time, and deleting the plurality of second preset cache entities to be deleted.

8. A cache device based on dual cache regions, the cache device based on dual cache regions comprising:

the acquisition module is used for acquiring a cache request of a target terminal;

the judging module is used for judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request;

a write-in module, configured to obtain a write mapping structure cache entity if the cache request belongs to the write-in cache request, and write the write mapping structure cache entity into a preset cache region in a thread sharing write-in manner or a thread isolation write-in manner, where the preset cache region includes a preset thread sharing cache region and a preset thread isolation cache region;

a reading module, configured to obtain a target preset mapping structure cache entity from a preset cache region and read the target preset mapping structure cache entity in a thread sharing reading manner or a thread isolation reading manner if the cache request belongs to the read cache request, where the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity obtained from the preset thread sharing cache region in the thread sharing reading manner, and the second target preset mapping structure cache entity is a preset mapping structure cache entity obtained from the preset thread isolation cache region in the thread isolation reading manner;

and a deleting module, where the cache request belongs to the delete cache request, and is used to acquire a plurality of preset cache entities to be deleted in a preset cache region by adopting a thread sharing delete mode or a thread isolation delete mode, and delete the plurality of preset cache entities to be deleted, where the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in the preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in the preset thread isolation cache region.

9. A cache device based on dual cache regions, the cache device comprising: a memory having instructions stored therein and at least one processor, the memory and the at least one processor interconnected by a line;

the at least one processor invoking the instructions in the memory to cause the dual-cache-region-based caching apparatus to perform the dual-cache-region-based caching method of any one of claims 1-7.

10. A computer-readable storage medium, having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the dual-cache-region-based caching method according to any one of claims 1 to 7.

Technical Field

The present invention relates to the field of cloud technologies, and in particular, to a cache method, apparatus, device, and storage medium based on dual cache regions.

Background

With the development of science and technology, various data caches are generated when people surf the internet, and more data caches are generated due to too many browsed webpages, so that how to better cache data becomes a problem to be solved urgently. Currently, the hash map (HashMap) in java and some open-source local cache frames are used as local caches.

In the prior art, the local global cache is not suitable for being used in a thread isolation sharing scene, the limitation is large, an open-source cache frame is too heavy, and the flexibility of the cache is low.

Disclosure of Invention

The invention mainly aims to solve the problems of large limitation and low flexibility in data caching.

The first aspect of the present invention provides a caching method based on dual cache regions, including: obtaining a cache request of a target terminal; judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request; if the cache request belongs to the write-in cache request, obtaining a write-in mapping structure cache entity, and writing the write-in mapping structure cache entity into a preset cache region by adopting a thread sharing write-in mode or a thread isolation write-in mode, wherein the preset cache region comprises a preset thread sharing cache region and a preset thread isolation cache region; if the cache request belongs to the read cache request, acquiring a target preset mapping structure cache entity and reading the target preset mapping structure cache entity from a preset cache region by adopting a thread sharing read mode or a thread isolation read mode, wherein the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity acquired from the preset thread sharing cache region by adopting the thread sharing read mode, and the second target preset mapping structure cache entity is a preset mapping structure cache entity acquired from the preset thread isolation cache region by adopting the thread isolation read mode; if the cache request belongs to the cache deletion request, acquiring a plurality of preset cache entities to be deleted in a preset cache region by adopting a thread sharing deletion mode or a thread isolation deletion mode, and deleting the plurality of preset cache entities to be deleted, wherein the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in the preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in the preset thread isolation cache region.

Optionally, in a first implementation manner of the first aspect of the present invention, if the cache request belongs to the write cache request, obtaining a write mapping structure cache entity, and writing the write mapping structure cache entity into a preset cache region in a thread sharing write mode or a thread isolation write mode, where the preset cache region includes a preset thread sharing cache region and a preset thread isolation cache region, where the preset cache region includes: if the cache request belongs to the write-in cache request, judging whether a preset cache region exists, if not, establishing a preset thread isolation cache region, and then establishing a preset thread sharing cache region to obtain a preset cache region; acquiring an initial write mapping structure cache entity according to the write cache request, and determining a write logic type according to the initial write mapping structure cache entity; judging whether the writing mode of the writing cache request is a thread sharing writing mode or a thread isolation writing mode according to the writing logic type; if the writing mode of the writing cache request is judged to be a thread sharing writing mode, adjusting the state of the preset thread sharing cache region to be a temporary reading and writing state, adjusting the initial writing mapping structure cache entity to obtain a writing mapping structure cache entity, and writing the writing mapping structure cache entity into the preset thread sharing cache region; and if the writing mode of the writing cache request is judged to be a thread isolation writing mode, adjusting the initial writing mapping structure cache entity to obtain a writing mapping structure cache entity, and writing the writing mapping structure cache entity into a preset thread isolation cache region.

Optionally, in a second implementation manner of the first aspect of the present invention, the obtaining, according to the write cache request, an initial write mapping structure cache entity, and determining, according to the initial write mapping structure cache entity, a write logic type includes: determining a cache handle according to the write-in cache request, and matching a corresponding first mapping structure cache entity according to the cache handle; adding a key value into the first mapping structure cache entity to generate a second mapping structure cache entity, wherein the key value is used for storing the content value of the first mapping structure cache entity; adding effective duration in the second mapping structure cache entity to generate a third mapping structure cache entity; adding an updating time into the third mapping structure cache entity to generate an initial writing mapping structure cache entity, and determining a writing logic type according to the initial writing mapping structure cache entity, wherein the effective duration and the updating time are used for judging whether the initial writing mapping structure is overtime and invalid.

Optionally, in a third implementation manner of the first aspect of the present invention, if it is determined that the write mode of the write cache request is a thread isolation write mode, adjusting the initial write mapping structure cache entity to obtain a write mapping structure cache entity, and writing the write mapping structure cache entity into a preset thread isolation cache region includes: if the writing mode of the writing cache request is judged to be a thread isolation writing mode, matching the initial writing mapping structure cache entity with a plurality of preset writing threads in the preset thread isolation cache region to obtain a target writing thread; judging whether the target write-in thread has a corresponding write-in sub-cache region in the preset thread isolation cache region; if the write-in sub-cache region corresponding to the target write-in thread does not exist in the preset thread isolation cache region, establishing a write-in sub-cache region corresponding to the target write-in thread to obtain a target write-in sub-cache region; and adjusting the updating time of the initial write mapping structure cache entity to be the current time to obtain a write mapping structure cache entity, and storing the write mapping structure cache entity into the target write sub-cache region, wherein the target write sub-cache region is arranged in the preset thread isolation cache region.

Optionally, in a fourth implementation manner of the first aspect of the present invention, if the cache request belongs to the read cache request, obtaining a target preset mapping structure cache entity and reading the target preset mapping structure cache entity from a preset cache region in a thread sharing read manner or a thread isolation read manner, where the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity obtained from a preset thread sharing cache region in a thread sharing read manner, and the second target preset mapping structure cache entity is a preset mapping structure cache entity obtained from a preset thread isolation cache region in a thread isolation read manner, and the method includes: if the cache request belongs to the read cache request, extracting a read handle based on the cache request; determining a read logic type based on the read handle, and judging whether a read mode of the read cache request is a thread sharing read mode or a thread isolation read mode based on the read logic type; if the reading mode of the reading cache request is the thread sharing reading mode, adjusting the state of the preset thread sharing cache area to be a temporary reading-writing state, acquiring a first target preset mapping structure cache entity from the preset thread sharing cache area, and reading the first target preset mapping structure cache entity; and if the reading mode of the reading cache request is the thread isolation reading mode, acquiring a second target preset mapping structure cache entity from the preset thread isolation cache region, and reading the second target preset mapping structure cache entity.

Optionally, in a fifth implementation manner of the first aspect of the present invention, if the reading manner of the read cache request is the thread isolation reading manner, acquiring a second target preset mapping structure cache entity from the preset thread isolation cache region, and reading the second target preset mapping structure cache entity includes: if the reading mode of the reading cache request is the thread isolation reading mode, determining a target reading thread in a plurality of preset reading threads of the preset thread isolation cache region; extracting a target reading sub-thread according to the target reading thread, and reading a second target preset mapping structure cache entity from the target reading sub-thread; acquiring a preset effective duration, a preset updating moment and a current moment of a cache entity of the second target preset mapping structure, summing the preset effective duration and the preset updating moment to obtain a failure moment, and judging whether the current moment is greater than the failure moment; and if the current time is greater than the failure time, setting the second target preset mapping structure cache entity as a null value.

Optionally, in a sixth implementation manner of the first aspect of the present invention, if the cache request of the target terminal belongs to the cache deletion request, a thread sharing deletion manner or a thread isolation deletion manner is adopted, a plurality of preset cache entities to be deleted are obtained in a preset cache region, and the plurality of preset cache entities to be deleted are deleted, where the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in the preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in the preset thread isolation cache region, and the method includes: if the cache request belongs to the cache deletion request and a thread sharing deletion mode is adopted to delete a preset cache request entity to be deleted, the state of a preset thread sharing cache area is adjusted to be a temporary read-write state, and a plurality of preset cache entities in the preset thread sharing cache area are traversed based on the updating time, the effective duration and the current time, a plurality of first preset cache entities to be deleted are determined, and the first preset cache entities to be deleted are deleted; if the cache request belongs to the cache deletion request and a thread isolation deletion mode is adopted to delete a preset cache request entity to be deleted, traversing a plurality of sub-cache regions in the preset thread isolation cache region, determining a second preset cache entity to be deleted in the plurality of sub-cache regions based on the updating time, the effective duration and the current time, and deleting the plurality of second preset cache entities to be deleted.

The second aspect of the present invention provides a cache apparatus based on dual cache regions, including: the acquisition module is used for acquiring a cache request of a target terminal; the judging module is used for judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request; a write-in module, configured to obtain a write mapping structure cache entity if the cache request belongs to the write-in cache request, and write the write mapping structure cache entity into a preset cache region in a thread sharing write-in manner or a thread isolation write-in manner, where the preset cache region includes a preset thread sharing cache region and a preset thread isolation cache region; a reading module, configured to obtain a target preset mapping structure cache entity from a preset cache region and read the target preset mapping structure cache entity in a thread sharing reading manner or a thread isolation reading manner if the cache request belongs to the read cache request, where the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity, the first target preset mapping structure cache entity is a preset mapping structure cache entity obtained from the preset thread sharing cache region in the thread sharing reading manner, and the second target preset mapping structure cache entity is a preset mapping structure cache entity obtained from the preset thread isolation cache region in the thread isolation reading manner; and a deleting module, where the cache request belongs to the delete cache request, and is used to acquire a plurality of preset cache entities to be deleted in a preset cache region by adopting a thread sharing delete mode or a thread isolation delete mode, and delete the plurality of preset cache entities to be deleted, where the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted, the plurality of first preset cache entities to be deleted are preset cache entities cached in the preset thread sharing cache region, and the plurality of second preset cache entities to be deleted are preset cache entities cached in the preset thread isolation cache region.

Optionally, in a first implementation manner of the second aspect of the present invention, the writing module specifically includes: a first judging unit, configured to judge whether a preset cache region exists if the cache request belongs to the write-in cache request, and if the preset cache region does not exist, establish a preset thread isolation cache region first, and then establish a preset thread sharing cache region to obtain a preset cache region; an obtaining unit, configured to obtain an initial write mapping structure cache entity according to the write cache request, and determine a write logic type according to the initial write mapping structure cache entity; a second judging unit, configured to judge whether a write mode of the write cache request is a thread sharing write mode or a thread isolation write mode according to the write logic type; a shared write-in unit, configured to adjust a state of the preset thread shared cache region to a temporary read-write state if it is determined that the write-in mode of the write-in cache request is a thread shared write-in mode, adjust the initial write mapping structure cache entity to obtain a write mapping structure cache entity, and write the write mapping structure cache entity into the preset thread shared cache region; and the isolation writing unit is used for adjusting the initial writing mapping structure cache entity to obtain a writing mapping structure cache entity and writing the writing mapping structure cache entity into a preset thread isolation cache region if the writing mode of the writing cache request is judged to be the thread isolation writing mode.

Optionally, in a second implementation manner of the second aspect of the present invention, the obtaining unit is specifically configured to: determining a cache handle according to the write-in cache request, and matching a corresponding first mapping structure cache entity according to the cache handle; adding a key value into the first mapping structure cache entity to generate a second mapping structure cache entity, wherein the key value is used for storing the content value of the first mapping structure cache entity; adding effective duration in the second mapping structure cache entity to generate a third mapping structure cache entity; adding an updating time into the third mapping structure cache entity to generate an initial writing mapping structure cache entity, and determining a writing logic type according to the initial writing mapping structure cache entity, wherein the effective duration and the updating time are used for judging whether the initial writing mapping structure is overtime and invalid.

Optionally, in a third implementation manner of the second aspect of the present invention, the isolated write unit is specifically configured to: if the writing mode of the writing cache request is judged to be a thread isolation writing mode, matching the initial writing mapping structure cache entity with a plurality of preset writing threads in the preset thread isolation cache region to obtain a target writing thread; judging whether the target write-in thread has a corresponding write-in sub-cache region in the preset thread isolation cache region; if the write-in sub-cache region corresponding to the target write-in thread does not exist in the preset thread isolation cache region, establishing a write-in sub-cache region corresponding to the target write-in thread to obtain a target write-in sub-cache region; and adjusting the updating time of the initial write mapping structure cache entity to be the current time to obtain a write mapping structure cache entity, and storing the write mapping structure cache entity into the target write sub-cache region, wherein the target write sub-cache region is arranged in the preset thread isolation cache region.

Optionally, in a fourth implementation manner of the second aspect of the present invention, the reading module specifically includes: a reading unit, configured to extract a read handle based on the cache request if the cache request belongs to the read cache request; a third judging unit, configured to determine a read logic type based on the read handle, and judge whether a read mode of the read cache request is a thread-sharing read mode or a thread-isolation read mode based on the read logic type; a shared reading unit, configured to adjust a state of the preset thread shared cache region to a temporary read-write state if the reading mode of the read cache request is the thread shared reading mode, and obtain a first target preset mapping structure cache entity from the preset thread shared cache region and read the first target preset mapping structure cache entity; and the isolation reading unit is used for acquiring a second target preset mapping structure cache entity from the preset thread isolation cache region and reading the second target preset mapping structure cache entity if the reading mode of the reading cache request is the thread isolation reading mode.

Optionally, in a fifth implementation manner of the second aspect of the present invention, the isolation reading unit is specifically configured to: if the reading mode of the reading cache request is the thread isolation reading mode, determining a target reading thread in a plurality of preset reading threads of the preset thread isolation cache region; extracting a target reading sub-thread according to the target reading thread, and reading a second target preset mapping structure cache entity from the target reading sub-thread; acquiring a preset effective time, a preset updating time and a current time of a second target preset mapping structure cache entity, summing the preset effective time and the preset updating time to obtain a failure time, and judging whether the current time is greater than the failure time; and if the current time is greater than the failure time, setting the second target preset mapping structure cache entity as a null value.

Optionally, in a sixth implementation manner of the second aspect of the present invention, the deleting module is specifically configured to: if the cache request belongs to the cache deletion request and a thread sharing deletion mode is adopted to delete a preset cache request entity to be deleted, the state of a preset thread sharing cache area is adjusted to be a temporary read-write state, and a plurality of preset cache entities in the preset thread sharing cache area are traversed based on the updating time, the effective duration and the current time, a plurality of first preset cache entities to be deleted are determined, and the first preset cache entities to be deleted are deleted; if the cache request belongs to the cache deletion request and a thread isolation deletion mode is adopted to delete a preset cache request entity to be deleted, traversing a plurality of sub-cache regions in the preset thread isolation cache region, determining a second preset cache entity to be deleted in the plurality of sub-cache regions based on the updating time, the effective duration and the current time, and deleting the plurality of second preset cache entities to be deleted.

A third aspect of the present invention provides a cache device based on dual cache regions, including: a memory having instructions stored therein and at least one processor, the memory and the at least one processor interconnected by a line; the at least one processor invokes the instructions in the memory to cause the dual-cache-region-based caching device to perform the dual-cache-region-based caching method described above.

A fourth aspect of the present invention provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to perform the above-mentioned dual-cache-region-based caching method.

According to the technical scheme provided by the invention, a cache request of a target terminal is obtained; judging whether the cache request belongs to a write cache request, a read cache request or a delete cache request; if the cache request belongs to the write-in cache request, obtaining a write-in mapping structure cache entity, and writing the write-in mapping structure cache entity into a preset cache region by adopting a thread sharing write-in mode or a thread isolation write-in mode, wherein the preset cache region comprises a preset thread sharing cache region and a preset thread isolation cache region; if the cache request belongs to the read cache request, acquiring a target preset mapping structure cache entity from a preset cache region in a thread sharing read mode or a thread isolation read mode and reading the target preset mapping structure cache entity, wherein the target preset mapping structure cache entity is a first target preset mapping structure cache entity or a second target preset mapping structure cache entity; if the cache request belongs to the cache deletion request, acquiring a plurality of preset cache entities to be deleted in a preset cache region by adopting a thread sharing deletion mode or a thread isolation deletion mode, and deleting the plurality of preset cache entities to be deleted, wherein the plurality of preset cache entities to be deleted are a plurality of first preset cache entities to be deleted or a plurality of second preset cache entities to be deleted. In the embodiment of the invention, the cache entity is cached by using the cache mode of thread sharing and the cache mode of thread isolation, and the overtime mechanism and the cache mechanism are arranged, so that data can be stored in different cache regions according to different cache requests and different cache logic types, the flexibility of caching is improved, the limitation of data caching is reduced, and the overtime cache entity can be automatically cleared.

Drawings

FIG. 1 is a diagram illustrating an embodiment of a caching method based on dual cache regions according to an embodiment of the present invention;

FIG. 2 is a diagram of another embodiment of a caching method based on dual cache regions according to the embodiment of the present invention;

FIG. 3 is a diagram of an embodiment of a cache device based on dual cache regions according to the embodiment of the present invention;

FIG. 4 is a diagram of another embodiment of a cache device based on dual cache regions according to the embodiment of the present invention;

fig. 5 is a schematic diagram of an embodiment of a cache device based on dual cache regions in the embodiment of the present invention.

Detailed Description

The embodiment of the invention provides a caching method, a caching device, caching equipment and a caching medium based on double cache regions, which are used for caching a cache entity by utilizing a thread sharing caching mode and a thread isolating caching mode, so that the limitation of data caching is reduced, and the flexibility of data caching is improved.

23页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种存储系统、文件存储和读取方法及终端设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类