Giter VIP home page Giter VIP logo

ziglang-caches's Introduction

ziglang-caches

This is a modern cache implementation, inspired by the following papers, provides high efficiency.

This offers state-of-the-art efficiency and scalability compared to other LRU-based cache algorithms.

Basic usage

[!LRU_Cache] Least recents used cache eviction policy for cache your data in-memory for fast access.

const std = @import("std");
const lru = @import("lru");

const cache = lru.LruCache(.locking, u8, []const u8);

pub fn main() !void {

    // Create a cache backed by DRAM
    var lrucache = try cache.init(std.heap.page_allocator, 4);
    defer lrucache.deinit();

    // Add an object to the cache
    try lrucache.insert(1, "one");
    try lrucache.insert(2, "two");
    try lrucache.insert(3, "three");
    try lrucache.insert(4, "four");

    // Most recently used cache
    std.debug.print("mru: {s} \n", .{lrucache.mru().?.value});

    // least recently used cache
    std.debug.print("lru: {s} \n", .{lrucache.lru().?.value});

    // remove from cache
    _ = lrucache.remove(1);

    // Check if an object is in the cache O/P: false
    std.debug.print("key: 1 exists: {} \n", .{lrucache.contains(1)});
}

๐Ÿš€ Usage

  1. Add ziglang-caches as a dependency in your build.zig.zon.

    build.zig.zon example
    .{
        .name = "<name_of_your_package>",
        .version = "<version_of_your_package>",
        .dependencies = .{
            .caches = .{
                .url = "https://github.com/jeevananthan-23/ziglang-caches/archive/<git_tag_or_commit_hash>.tar.gz",
                .hash = "<package_hash>",
            },
        },
    }

    Set <package_hash> to 12200000000000000000000000000000000000000000000000000000000000000000, and Zig will provide the correct found value in an error message.

  2. Add lrucache as a module in your build.zig.

    build.zig example
    const lrucache = b.dependency("caches", .{});
    exe.addModule("lrucache", lrucache.module("lrucache"));

ziglang-caches's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.