Git Product home page Git Product logo

robinson's Introduction

MIT license lint workflow help wanted

Robinson

Overview

The "Robinson" package is a lightweight and efficient Go library that provides a thread-safe cache implementation for storing and retrieving values of any type. It offers a simple and minimalistic approach to caching, leveraging the power of Go generics to ensure strong typing and optimal performance.

Features

  • Thread-Safe Caching: The Robinson package offers a thread-safe cache that allows concurrent access from multiple goroutines without the risk of data corruption or race conditions. It provides synchronized operations to ensure safe and reliable caching in concurrent environments.
  • Strong Typing: With Go generics, the cache enforces strong typing, meaning that once the cache is created, it can only store and retrieve values of the exact type specified during initialization. This ensures type safety and prevents accidental data mismatches or type-related errors.
  • Error-Free Operation: The Robinson library is designed to provide a seamless and error-free caching experience. It handles internal operations and resource management efficiently, reducing the possibility of unexpected errors or exceptions during cache operations.
  • Zero Dependencies: The package has been developed to be lightweight and self-contained, with no external dependencies. It minimizes the overall package size and simplifies integration into your projects, avoiding potential conflicts or compatibility issues with other libraries.

Installation

To install the Robinson package, use the following command:

go get github.com/kaatinga/robinson

Usage

To use the Robinson package in your Go projects, import it into your code:

import "github.com/kaatinga/robinson"

To create a new cache, use the NewCrusoe() function:

value := 123

// Create a cache for storing integer value
crusoe := NewCrusoe[int]()

// Set the value in the cache
crusoe.Set(value)

// Get the value from the cache
cacheValue := crusoe.Get()

To apply atomic operations to the cache, use the Call() method:

value := 123

// Create a cache for storing integer value
crusoe := NewCrusoe[int]()
crusoe.Set(value)

// Increment the value in the cache
crusoe.Call(func(v int) int {
    return v + 1
})

or you can use CallWithError() method:

value := 123

// Create a cache for storing integer value
crusoe := NewCrusoe[int]()
crusoe.Set(value)

// Increment the value in the cache
crusoe.CallWithError(func(v int) (int, error) {
	if v == 0 {
		return 0, errors.New("value is zero")
	}
    return v + 1, nil
})

In this particular case you might use atomic package to increment value, but it's just an example. The passed function may be intricate and complex as well as the value type.

Whether you need to implement a simple in-memory cache for your application or require a thread-safe caching solution for concurrent operations, the Robinson package provides a reliable and efficient caching mechanism. Its minimalistic design, strong typing, and error-free operation make it a valuable tool for improving performance and enhancing data management in your Go projects.

License

The "Robinson" package is an open-source software released under the MIT License. The original author is Michael Gunkoff.

Contributing

If you want to contribute to the project, please read the Contributing Guide.

robinson's People

Contributors

kaatinga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

achillesxu

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.