CN112115074A - 一种使用自动加载机制实现数据常驻内存方法 - Google Patents

一种使用自动加载机制实现数据常驻内存方法 Download PDF

Info

Publication number
CN112115074A
CN112115074A CN202010910916.6A CN202010910916A CN112115074A CN 112115074 A CN112115074 A CN 112115074A CN 202010910916 A CN202010910916 A CN 202010910916A CN 112115074 A CN112115074 A CN 112115074A
Authority
CN
China
Prior art keywords
cache
data
automatic loading
resident memory
loading mechanism
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010910916.6A
Other languages
English (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.)
Unicloud Nanjing Digital Technology Co Ltd
Original Assignee
Unicloud Nanjing Digital 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 Unicloud Nanjing Digital Technology Co Ltd filed Critical Unicloud Nanjing Digital Technology Co Ltd
Priority to CN202010910916.6A priority Critical patent/CN112115074A/zh
Publication of CN112115074A publication Critical patent/CN112115074A/zh
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0893Caches characterised by their organisation or structure
    • G06F12/0895Caches characterised by their organisation or structure of parts of caches, e.g. directory or tag array
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/12Replacement control
    • G06F12/121Replacement control using replacement algorithms
    • G06F12/122Replacement control using replacement algorithms of the least frequently used [LFU] type, e.g. with individual count value
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1032Reliability improvement, data loss prevention, degraded operation etc

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种使用自动加载机制实现数据常驻内存方法,包括步骤,获取到拦截方法的Cache注解,并生成缓存key;通过缓存key,去缓存中获取数据;通过自动加载处理器AutoLoadHandler,当缓存即将过期时,获取数据,并将数据放到缓存中。为了防止自动加载队列过大,设置了容量限制;同时会将超过一定时间没有用户请求的也会从自动加载队列中移除,把服务器资源释放出来,给真正需要的请求。避免在请求高峰时,因为缓存失效,而造成数据库压力无法承受的问题。

Description

一种使用自动加载机制实现数据常驻内存方法
技术领域
本发明涉及计算机数据处理领域,具体涉及一种使用自动加载机制实现数据常驻内存方法及分离方法。
背景技术
缓存可以说是无处不在,比如PC电脑中的内存、CPU中的二级缓存、数据库IO占用、HTTP协议中的缓存控制、CDN加速技术都是使用了缓存的思想来解决性能问题。
缓存又分进程内缓存和分布式缓存两种,现在使用的缓存技术多种多样,比如Redis、Memcache、EhCache等,甚至还有使用ConcurrentHashMap或HashTable来实现缓存。但在缓存的使用上,每个都有自己的实现方式,大部分是直接与业务代码绑定,随着业务的变化,要更换缓存方案。人们在使用缓存的大部分情况下,都是把缓存操作和业务逻辑的代码交织在一起,这样会引起如下几个问题:
1.缓存操作非常繁琐,产生非常多的重复代码。
2.缓存操作与业务逻辑耦合度非常高,不利于后期的维护。
3.当业务数据为null时,无法确定是否已经缓存,会造成缓存无法命中。
4.开发阶段,为了排查问题,经常需要来回开关缓存功能,使用上面的代码是无法做到很方便地开关缓存功能。
5.当业务越来越复杂,使用缓存的地方越来越多时,很难定位哪些数据要进行主动删除。
6.如果不想用Redis,换用别的缓存技术的话,就特别的麻烦。
因此基于Redis缓存技术的以上几点不足,我们有必要针对现有技术的不足而提供一种使用自动加载机制实现数据常驻内存方法。
发明内容
为了克服现有技术中的不足,本发明提出一种使用自动加载机制实现数据常驻内存方法,其能够有效减轻数据库的压力。
为了实现上述目的,本发明提出一种使用自动加载机制实现数据常驻内存方法,包括如下步骤,
S1、获取到拦截方法的Cache注解,并生成缓存key;
S2、通过缓存key,去缓存中获取数据。
优选的,如果缓存被访问的数据命中则进行步骤S3,S3包括,
S301、如果需要自动加载,则请求相关参数,封装到AutoLoad中,并放到AutoLoadHandler中,把相关信息保存到自动加载队列中;
S302、如果不需要自动加载,则判断缓存是否即将过期,当缓存即将过期,则发起异步刷新;
S303、把数据返回给用户。
优选的,如果缓存没有被访问的数据命中则进行步骤S4,S4包括,
S401、选举出一个leader回到数据源中去加载数据,加载到数据后通知其它请求从内存中获取数据;
S402、leader负责把数据写入缓存;如果需要自动加载,则把相关信息保存到自动加载队列中;
S403、把数据返回给用户。
本发明具有以下有益效果:
通过自动加载处理器AutoLoadHandler,当缓存即将过期时,获取数据,并将数据放到缓存中。为了防止自动加载队列过大,设置了容量限制;同时会将超过一定时间没有用户请求的也会从自动加载队列中移除,把服务器资源释放出来,给真正需要的请求。避免在请求高峰时,因为缓存失效,而造成数据库压力无法承受的问题。
附图说明
下面结合附图对本发明作进一步描写和阐述。
图1为实现一种使用自动加载机制实现数据常驻内存方法工作原理图。
具体实施方式
下面将结合附图、通过对本发明的优选实施方式的描述,更加清楚、完整地阐述本发明的技术方案。
实施例。
如图1所示,本发明提出的一种使用自动加载机制实现数据常驻内存方法,包括,
包括如下步骤,
S1、获取到拦截方法的Cache注解,并生成缓存key。
本实施例中主要采用AOP方法拦截Cache注解,利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。
S2、通过缓存key,去缓存中获取数据。
作为本发明的一种技术优化方案,如果缓存被访问的数据命中则进行步骤S3,S3包括,
S301、如果需要自动加载,则请求相关参数,封装到AutoLoad中,并放到AutoLoadHandler中,把相关信息保存到自动加载队列中。
本实施例中,AutoLoadHandler(自动加载处理器)主要做的事情:当缓存即将过期时,去执行DAO的方法,获取数据,并将数据放到缓存中。为了防止自动加载队列过大,设置了容量限制;同时会将超过一定时间没有用户请求的也会从自动加载队列中移除,把服务器资源释放出来,给真正需要的请求。
使用自加载的目的:
避免在请求高峰时,因为缓存失效,而造成数据库压力无法承受;把一些耗时业务得以实现;把一些使用非常频繁的数据,使用自动加载,因为这样的数据缓存失效时,最容易造成服务器的压力过大。
S302、如果不需要自动加载,则判断缓存是否即将过期,当缓存即将过期,则发起异步刷新。
S303、把数据返回给用户。
作为本发明的一种技术优化方案,如果缓存没有被访问的数据命中则进行步骤S4,S4包括,
S401、选举出一个leader回到数据源中去加载数据,加载到数据后通知其它请求从内存中获取数据。
S402、leader负责把数据写入缓存;如果需要自动加载,则把相关信息保存到自动加载队列中。
S403、把数据返回给用户。
AutoLoadCache是使用Spring AOP、Annotation以及Spring EL表达式来进行管理缓存的解决方案,实现缓存与业务逻辑的解耦,并增加异步刷新及“拿来主义机制”,以适应高并发环境下的使用。为了更好管理缓存增加了Magic模式,同时基于AOP实现自动加载机制来达到数据“常驻内存”的目的。
上述具体实施方式仅仅对本发明的优选实施方式进行描述,而并非对本发明的保护范围进行限定。在不脱离本发明设计构思和精神范畴的前提下,本领域的普通技术人员根据本发明所提供的文字描述、附图对本发明的技术方案所作出的各种变形、替代和改进,均应属于本发明的保护范畴。本发明的保护范围由权利要求确定。

Claims (3)

1.一种使用自动加载机制实现数据常驻内存方法,其特征在于:包括如下步骤,
S1、获取到拦截方法的Cache注解,并生成缓存key;
S2、通过缓存key,去缓存中获取数据。
2.根据权利要求1所述的一种使用自动加载机制实现数据常驻内存方法,其特征在于:如果缓存被访问的数据命中则进行步骤S3,S3包括,
S301、如果需要自动加载,则请求相关参数,封装到AutoLoad中,并放到AutoLoadHandler中,把相关信息保存到自动加载队列中;
S302、如果不需要自动加载,则判断缓存是否即将过期,当缓存即将过期,则发起异步刷新;
S303、把数据返回给用户。
3.根据权利要求1所述的一种使用自动加载机制实现数据常驻内存方法,其特征在于:如果缓存没有被访问的数据命中则进行步骤S4,S4包括,
S401、选举出一个leader回到数据源中去加载数据,加载到数据后通知其它请求从内存中获取数据;
S402、leader负责把数据写入缓存;如果需要自动加载,则把相关信息保存到自动加载队列中;
S403、把数据返回给用户。
CN202010910916.6A 2020-09-02 2020-09-02 一种使用自动加载机制实现数据常驻内存方法 Pending CN112115074A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010910916.6A CN112115074A (zh) 2020-09-02 2020-09-02 一种使用自动加载机制实现数据常驻内存方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010910916.6A CN112115074A (zh) 2020-09-02 2020-09-02 一种使用自动加载机制实现数据常驻内存方法

Publications (1)

Publication Number Publication Date
CN112115074A true CN112115074A (zh) 2020-12-22

Family

ID=73803956

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010910916.6A Pending CN112115074A (zh) 2020-09-02 2020-09-02 一种使用自动加载机制实现数据常驻内存方法

Country Status (1)

Country Link
CN (1) CN112115074A (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113722363A (zh) * 2021-08-19 2021-11-30 成都民航西南凯亚有限责任公司 缓存公共组件及其实现、安装与运行方法

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106021445A (zh) * 2016-05-16 2016-10-12 努比亚技术有限公司 一种加载缓存数据的方法及装置
CN109684086A (zh) * 2018-12-14 2019-04-26 广东亿迅科技有限公司 一种基于aop的分布式缓存自动加载方法及装置

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106021445A (zh) * 2016-05-16 2016-10-12 努比亚技术有限公司 一种加载缓存数据的方法及装置
CN109684086A (zh) * 2018-12-14 2019-04-26 广东亿迅科技有限公司 一种基于aop的分布式缓存自动加载方法及装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
MB5FE559619E363: "自动加载缓存框架", 《HTTPS://BLOG.51CTO.COM/U_15067222/4815185》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113722363A (zh) * 2021-08-19 2021-11-30 成都民航西南凯亚有限责任公司 缓存公共组件及其实现、安装与运行方法
CN113722363B (zh) * 2021-08-19 2023-09-12 成都民航西南凯亚有限责任公司 缓存公共组件及其实现、安装与运行方法

Similar Documents

Publication Publication Date Title
US7096213B2 (en) Persistent key-value repository with a pluggable architecture to abstract physical storage
US8380931B2 (en) Memory cache data center
JP5832608B2 (ja) キャッシュ・エントリの一致性検索のための確率テクニック
US8799213B2 (en) Combining capture and apply in a distributed information sharing system
JP5006348B2 (ja) 応答出力キャッシュに対するマルチキャッシュ協調
US10915554B2 (en) Database replication system
US20030115420A1 (en) Methods and apparatus for implementing a chche replacement scheme
CN112035528B (zh) 数据查询方法及装置
US8818942B2 (en) Database system with multiple layer distribution
US20110066791A1 (en) Caching data between a database server and a storage system
WO2020181810A1 (zh) 应用于集群内多级缓存的数据处理方法和装置
US8762651B2 (en) Maintaining cache coherence in a multi-node, symmetric multiprocessing computer
US9928174B1 (en) Consistent caching
CN112115074A (zh) 一种使用自动加载机制实现数据常驻内存方法
CN113767372A (zh) 执行多核处理器的多个数据请求
US11921683B2 (en) Use of time to live value during database compaction
US10726047B2 (en) Early thread return with secondary event writes
US20190205255A1 (en) Key invalidation in cache systems
US20200319915A1 (en) Disaggregated rack mount storage side transaction support
US11176039B2 (en) Cache and method for managing cache
TWI608360B (zh) 任務執行方法及任務調度系統
US20100217941A1 (en) Improving the efficiency of files sever requests in a computing device
US20230168924A1 (en) Apparatus for preloading data in distributed computing environment and method using the same
CN116048425B (zh) 一种分层缓存方法、系统及相关组件
US20240168645A1 (en) Methods and systems for limiting data traffic while processing computer system operations

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
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20201222