ttlmap

package module
v0.0.0-...-5bbd378 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 5 Imported by: 76

README

Build Status Build Status

TtlMap

Redis-like Map with expiry times and maximum capacity


import "github.com/mailgun/ttlmap"

mh, _ := ttlmap.NewMap(20)
mh.Set("key1", "value", 20)
valI, exists := mh.Get("key2")
if exists {
   val := valI.(string)
}

Documentation

Overview

Copyright 2017 Mailgun Technologies Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PQItem

type PQItem struct {
	Value    interface{}
	Priority int // The priority of the item in the queue.
	// contains filtered or unexported fields
}

An PQItem is something we manage in a priority queue.

type PriorityQueue

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

Implements a PriorityQueue

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

func (PriorityQueue) Len

func (p PriorityQueue) Len() int

func (*PriorityQueue) Peek

func (p *PriorityQueue) Peek() *PQItem

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() *PQItem

func (*PriorityQueue) Push

func (p *PriorityQueue) Push(el *PQItem)

func (*PriorityQueue) Remove

func (p *PriorityQueue) Remove(el *PQItem)

func (*PriorityQueue) Update

func (p *PriorityQueue) Update(el *PQItem, priority int)

Modifies the priority and value of an Item in the queue.

type TTLMap

type TTLMap struct {
	// Optionally specifies a callback function to be
	// executed when an entry has expired
	OnExpire func(key string, i interface{})
	// contains filtered or unexported fields
}

func NewTTLMap

func NewTTLMap(capacity int) *TTLMap

func (*TTLMap) Get

func (m *TTLMap) Get(key string) (interface{}, bool)

func (*TTLMap) GetInt

func (m *TTLMap) GetInt(key string) (int, bool, error)

func (*TTLMap) Increment

func (m *TTLMap) Increment(key string, value int, ttlSeconds int) (int, error)

func (*TTLMap) Len

func (m *TTLMap) Len() int

func (*TTLMap) RemoveExpired

func (m *TTLMap) RemoveExpired(iterations int) int

func (*TTLMap) RemoveLastUsed

func (m *TTLMap) RemoveLastUsed(iterations int)

func (*TTLMap) Set

func (m *TTLMap) Set(key string, value interface{}, ttlSeconds int) error

Jump to

Keyboard shortcuts

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