Coder Social home page Coder Social logo

memoryjar's Introduction

MemoryJar

MemoryJar is a fast and efficient and thread-safe persistent string caching library that includes capacity management (LRU) and support for age expiration. It utilizes both in-memory and disk storage, supporting asynchronous writes for speed. This library was inspired by the caching mechanism on the Parse iOS SDK.

This caching library is most useful when building a caching system for managing a REST API.

CI Status Version License Platform

Installation

To install it, simply add the following line to your Podfile:

pod "MemoryJar"

Usage

import MemoryJar

// use shared, or create your own with MemoryJar()
let cache = MemoryJar.shared

// Simple
cache["company"] = "Modernistik"
// retrieve (no expiration)
let company = cache["company"]

// Some API response
let json = """
{
    "name" : "Anthony Persaud",
    "id" : 7,
    "company" : {
        "name" : "Modernistik",
        "location": "San Diego, CA"
     }
}
"""

let cacheKey = "https://some.api/?id=7"

// set the value
cache.set(value: json, forKey: cacheKey)

// fetch value only if it is not older than 1 day.
if let result = cache.get(forKey: cacheKey, maxAge: 86400) {
    print(result)
}

// deletes all cache objects
cache.removeAllObjects()

Todo

  • Support clearing specific url paths matching a pattern.

Author

Anthony Persaud, https://www.modernistik.com

License

MemoryJar is available under the MIT license. See the LICENSE file for more info.

memoryjar's People

Contributors

apersaud avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

getheal

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.