Skip to content

Commit

Permalink
add v3 compatible with simplelru
Browse files Browse the repository at this point in the history
v2 had most of the required functions, so this change adds missing ones
to satisfy the simplelru interface.

To do that, RemoveOldest started returning parameters, unlike being void
as before.

Also, GetExpiration is added.
  • Loading branch information
paskal committed Feb 19, 2024
1 parent e81ac90 commit 0c8c094
Show file tree
Hide file tree
Showing 10 changed files with 918 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:

steps:
- name: set up go
uses: actions/setup-go@v3
uses: actions/setup-go@5
with:
go-version: "1.20"
id: go

- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@4

- name: build and test
run: |
Expand All @@ -33,7 +33,7 @@ jobs:
working-directory: v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
working-directory: v2
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/ci-v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: build-v3

on:
push:
branches:
tags:
paths:
- ".github/workflows/ci-v3.yml"
- "v3/**"
pull_request:
paths:
- ".github/workflows/ci-v3.yml"
- "v3/**"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: set up go
uses: actions/setup-go@5
with:
go-version: "1.20"
id: go

- name: checkout
uses: actions/checkout@4

- name: build and test
run: |
go test -timeout=60s -race -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov
go build -race
working-directory: v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
working-directory: v3

- name: install goveralls, submit coverage
run: |
go install github.com/mattn/goveralls@latest
goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: v3
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,37 @@ on:
tags:
paths-ignore:
- ".github/workflows/ci-v2.yml"
- ".github/workflows/ci-v3.yml"
- "v2/**"
- "v3/**"
pull_request:
paths-ignore:
- ".github/workflows/ci-v2.yml"
- ".github/workflows/ci-v3.yml"
- "v2/**"
- "v3/**"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: set up go
uses: actions/setup-go@v3
uses: actions/setup-go@5
with:
go-version: "1.20"
id: go

- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@4

- name: build and test
run: |
go test -timeout=60s -race -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov
go build -race
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ either using LRC or LRU eviction.
run cache.DeleteExpired periodically using [time.Ticker](https://golang.org/pkg/time/#Ticker),
advisable period is 1/2 of TTL.

This cache is heavily inspired by [hashicorp/golang-lru](https://github.com/hashicorp/golang-lru) _simplelru_ implementation. Key differences are:
This cache is heavily inspired by [hashicorp/golang-lru](https://github.com/hashicorp/golang-lru) _simplelru_ implementation. v3 implements `simplelru.LRUCache` interface, so if you use a subset of functions, so you can use all functions except for that interchangeable and switch between this package and `github.com/hashicorp/golang-lru/v2/simplelru` or `github.com/hashicorp/golang-lru/v2/expirable` without any changes in your code. Key differences are:

- Support LRC (Least Recently Created) in addition to LRU and TTL-based eviction
- Supports per-key TTL setting
Expand Down
44 changes: 44 additions & 0 deletions v3/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
linters-settings:
govet:
check-shadowing: true
gocyclo:
min-complexity: 15
misspell:
locale: US
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc

linters:
enable:
- gocritic
- megacheck
- revive
- govet
- unconvert
- megacheck
- gas
- gocyclo
- dupl
- misspell
- unused
- typecheck
- ineffassign
- stylecheck
- gochecknoinits
- exportloopref
- nakedret
- gosimple
- prealloc
fast: false
disable-all: true

run:
output:
format: tab
skip-dirs:
- vendor
Loading

0 comments on commit 0c8c094

Please sign in to comment.