cache

package module
v0.0.0-...-a3cae15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 1 Imported by: 0

README

go-cache

go-cache — это легковесная in-memory библиотека кеша для Go. Она позволяет сохранять, получать и удалять данные по ключу, используя встроенные механизмы синхронизации для многопоточной безопасности.

Установка

Чтобы установить пакет, выполните:

go get github.com/yourusername/go-cache
package main

import (
    "fmt"
    "github.com/yourusername/go-cache"
)

func main() {
    // Создаем новый кеш
    cache := cache.New()

    // Устанавливаем значение по ключу
    cache.Set("userId", 42)

    // Получаем значение по ключу
    userId := cache.Get("userId")
    fmt.Println(userId) // Output: 42

    // Удаляем значение по ключу
    cache.Delete("userId")

    // Пробуем снова получить значение
    userId = cache.Get("userId")
    fmt.Println(userId) // Output: <nil>
}

Методы

  • Set(key string, value interface{}): Добавляет значение в кеш по указанному ключу.
  • Get(key string): Возвращает значение по ключу, или nil, если ключ не найден.
  • Delete(key string): Удаляет значение по ключу.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func New

func New() *Cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL