All Projects → GitHawkApp → Flatcache

GitHawkApp / Flatcache

Licence: mit
Implementation of Soroush Khanlou's Flat Cache.

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Flatcache

Layercache
Caching made simple for Android and Java.
Stars: ✭ 155 (-10.4%)
Mutual labels:  cache
Haproxy
HAProxy Load Balancer's development branch (mirror of git.haproxy.org)
Stars: ✭ 2,463 (+1323.7%)
Mutual labels:  cache
Http Cache Semantics
RFC 7234 in JavaScript. Parses HTTP headers to correctly compute cacheability of responses, even in complex cases
Stars: ✭ 169 (-2.31%)
Mutual labels:  cache
Cacheable Response
An HTTP compliant route path middleware for serving cache response with invalidation support.
Stars: ✭ 157 (-9.25%)
Mutual labels:  cache
Lru Cache
💫 A feature complete LRU cache implementation in C++
Stars: ✭ 162 (-6.36%)
Mutual labels:  cache
Q Municate Ios
Q-municate iOS repository
Stars: ✭ 164 (-5.2%)
Mutual labels:  cache
Android Cache Fix Gradle Plugin
Gradle plugin to fix Android caching problems
Stars: ✭ 150 (-13.29%)
Mutual labels:  cache
Nginx Helper
Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
Stars: ✭ 170 (-1.73%)
Mutual labels:  cache
Cachemanager
CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
Stars: ✭ 2,049 (+1084.39%)
Mutual labels:  cache
Holster
A place to keep useful golang functions and small libraries
Stars: ✭ 166 (-4.05%)
Mutual labels:  cache
Study
全栈工程师学习笔记;Spring登录、shiro登录、CAS单点登录和Spring boot oauth2单点登录;Spring data cache 缓存,支持Redis和EHcahce; web安全,常见web安全漏洞以及解决思路;常规组件,比如redis、mq等;quartz定时任务,支持持久化数据库,动态维护启动暂停关闭;docker基本用法,常用image镜像使用,Docker-MySQL、docker-Postgres、Docker-nginx、Docker-nexus、Docker-Redis、Docker-RabbitMQ、Docker-zookeeper、Docker-es、Docker-zipkin、Docker-ELK等;mybatis实践、spring实践、spring boot实践等常用集成;基于redis的分布式锁;基于shared-jdbc的分库分表,支持原生jdbc和Spring Boot Mybatis
Stars: ✭ 159 (-8.09%)
Mutual labels:  cache
Dataloader Php
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
Stars: ✭ 160 (-7.51%)
Mutual labels:  cache
Springbootlearning
《Spring Boot教程》源码
Stars: ✭ 2,065 (+1093.64%)
Mutual labels:  cache
Cachew
Transparent and persistent cache/serialization powered by type hints
Stars: ✭ 155 (-10.4%)
Mutual labels:  cache
Imagepipeline
Folio Image Pipeline is an image loading and caching framework for iOS clients
Stars: ✭ 170 (-1.73%)
Mutual labels:  cache
Libcache
A Lightweight in-memory key:value cache library for Go.
Stars: ✭ 152 (-12.14%)
Mutual labels:  cache
Xcode Clean.sh
Bash script freeing up disk space by removing Xcode generated data
Stars: ✭ 164 (-5.2%)
Mutual labels:  cache
Ktvhttpcache
A powerful media cache framework.
Stars: ✭ 2,113 (+1121.39%)
Mutual labels:  cache
Tmp Cache
A least-recently-used cache in 35 lines of code~!
Stars: ✭ 170 (-1.73%)
Mutual labels:  cache
Hitchcock
The Master of Suspense 🍿
Stars: ✭ 167 (-3.47%)
Mutual labels:  cache

FlatCache

Store any object in a flat cache by String id and notify listeners when changes occur.

This is an implementation of Soroush Khanlou's The Flat Cache blog post used in GitHawk.

Installation

Just add FlatCache to your Podfile and pod install. Done!

pod 'FlatCache'

Usage

Add the Cachable protocol to models that you want to store in the cache. Conform to the protocol by returning a String identifier used for lookup.

struct User {
  let name: String
}

extension User: Cachable {
  var id: String {
    return name
  }
}

Don't worry about id collisions between objects. The cache "namespaces" different models by type.

Now just create a FlatCache object and start reading & writing with it.

let cache = FlatCache()
let user = User(name: "ryan")
cache.set(value: user)
if let cached = cache.get(id: user.id) as User? {
  print(cached.name) // "ryan"
}

FlatCache uses the type information with the get(id:) function to lookup the appropriate object. You must type the result somehow.

Listeners

One of the strengths of FlatCache is adding "listeners" to the cache to be notified when an object is changed. This powerful tool lets multiple systems respond to object changes.

let cache = FlatCache()
let user = User(name: "ryan")
let listener = MyUserListener()
cache.add(listener: listener, value: user)

Now whenever user is set again in the cache, MyUserListener will be notified with the following function:

func flatCacheDidUpdate(cache: FlatCache, update: FlatCache.Update) {
  switch update {
  case .item(let item):
    // just a single object updated
  case .list:
    // a list of subscribed objects updated
  }
}

FlatCache coalesces so only a single event is delivered when something changes, no matter if an update has just a single object or hundreds.

Acknowledgements

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].