Code Monkey home page Code Monkey logo

kitura-cache's Introduction

Kitura

APIDoc Build Status - Master macOS Linux Apache 2 Slack Status

KituraCache

KituraCache is an in-memory, thread-safe cache which allows you to store objects against a unique, Hashable key.

Swift version

The latest version of KituraCache requires Swift 4.0 but recommends using 4.1.2 or newer. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

Usage

Add dependencies

Add the Kitura-Cache package to the dependencies within your application’s Package.swift file. Substitute "x.x.x" with the latest Kitura-Cache release.

.package(url: "https://github.com/Kitura/Kitura-Cache.git", from: "x.x.x")

Add KituraCache to your target's dependencies:

.target(name: "example", dependencies: ["KituraCache"]),

Import package

import KituraCache

Example

To use KituraCache, add the dependencies and import the package as defined above, then initialize:

let cache = KituraCache()

If no arguments are provided, the default cache will be non-expiring and a check will be made every 10 minutes to determine whether any entries need to be removed.

To add an entry to the cache, or update an entry if the key already exists:

In the following examples, item is a struct with an integer id field.

cache.setObject(item, forKey: item.id)

To retrieve an entry from the cache:

let cache = KituraCache()
...
if let item = cache.object(forKey: 1) {
    //Object with key of 1 retrieved from cache.
    ...
}
else {
    //No object stored in cache with key of 1.
    ...
}

To delete a single entry, pass the entry's key as a parameter:

cache.removeObject(forKey: 1)

To reset the cache and its Statistics:

cache.flush()

API Documentation

For more information visit our API reference.

Community

We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

kitura-cache's People

Contributors

bdhernand avatar dannys42 avatar dillan avatar djones6 avatar dunncoding avatar enriquel8 avatar helenmasters avatar ianpartridge avatar irar2 avatar kyemaloy97 avatar quanvo87 avatar shihabmehboob avatar shmuelk avatar vadimeisenbergibm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.