Giter Site home page Giter Site logo

geecache's Introduction

GeeCache

分布式缓存

v0.0.1
LRU 缓存淘汰策略

GeeCache 的缓存全部存储在内存中,内存是有限的,因此不可能无限制地添加数据。 假定我们设置缓存能够使用的内存大小为 N,那么在某一个时间点,添加了某一条缓存记录之后, 占用内存超过了 N,这个时候就需要从缓存中移除一条或多条数据了。那移除谁呢? 我们肯定希望尽可能移除“没用”的数据,那如何判定数据“有用”还是“没用”呢?

我们创建一个包含字典和双向链表的结构体类型 Cache,方便实现后续的增删查改操作

v0.0.2
实现 GeeCache 核心数据结构 Group,缓存不存在时,调用回调函数获取源数据

接收 key --> 检查是否被缓存 -----> 返回缓存值 ⑴
 | 否
   |-----> 是否应当从远程节点获取 -----> 与远程节点交互 --> 返回缓存值 ⑵
        | 否
            |-----> 调用回调函数,获取值并添加到缓存 --> 返回缓存值 ⑶

支持并发读写

我们思考一下,如果缓存不存在,应从数据源(文件,数据库等)获取数据并添加到缓存中。 GeeCache 是否应该支持多种数据源的配置呢?不应该,一是数据源的种类太多,没办法一一实现; 二是扩展性不好。如何从源头获取数据,应该是用户决定的事情,我们就把这件事交给用户好了。 因此,我们设计了一个回调函数(callback),在缓存不存在时,调用这个函数,得到源数据。

geecache's People

Contributors

lljjj-zed avatar

Stargazers

风渐隐 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.