Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: check
on:
push:
pull_request:
branches: [main]
pull_request_target:
types: [opened, synchronize, reopened]
branches: [main]
workflow_dispatch:

jobs:
Expand All @@ -15,9 +18,9 @@ jobs:
with:
version: latest
-
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v7
with:
version: latest
version: v2.2.0
-
run: go test ./...
shell: bash
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ on:
- '*'

name: "Create release"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
uses: kevincobain2000/action-gobrew@v2
- name: Set up Go
uses: actions/setup-go@v5
with:
version: latest
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
go-version: stable
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 24 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
version: "2"
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
default: none
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- dupl
- errcheck
- errorlint
- exportloopref
- goconst
- gocritic
- gocyclo
- goprintffuncname
- gosec
- govet
- ineffassign
- prealloc
- revive
- stylecheck
- staticcheck
- whitespace
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
11 changes: 9 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
version: 2

before:
hooks:
- go mod tidy

builds:
-
env:
- env:
- CGO_ENABLED=0
goos:
- linux
Expand All @@ -12,6 +14,11 @@ builds:
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
archives:
-
format: binary
Expand Down
71 changes: 71 additions & 0 deletions cache_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"fmt"
"time"
)

// Example of how to use the improved directory cache with performance monitoring
func ExampleCacheUsage() {
// Create custom cache configuration
cacheConfig := &CacheConfig{
TTL: 2 * time.Minute, // Longer TTL for better performance
CleanupInterval: 1 * time.Minute, // More frequent cleanup
MaxEntries: 500, // Smaller cache for this example
EnablePeriodicCleanup: true,
}

// Create cache with custom configuration
fs := &DefaultFileSystem{}
cache := NewDirCache(cacheConfig, fs)
defer cache.Close() // Important: close to stop cleanup goroutine

// Test some directory checks
testDirs := []string{
"/tmp",
"/etc",
"/var",
"/usr/bin",
"/nonexistent/dir",
}

fmt.Println("Testing directory cache performance...")

// First round - cache misses
start := time.Now()
for _, dir := range testDirs {
exists := cache.IsDirectoryNotEmpty(dir)
fmt.Printf("Directory %s exists and not empty: %v\n", dir, exists)
}
firstRoundTime := time.Since(start)

// Second round - cache hits (should be much faster)
start = time.Now()
for _, dir := range testDirs {
exists := cache.IsDirectoryNotEmpty(dir)
fmt.Printf("Directory %s exists and not empty: %v (cached)\n", dir, exists)
}
secondRoundTime := time.Since(start)

// Get and display cache statistics
stats := cache.GetStats()
fmt.Printf("\n=== Cache Performance Statistics ===\n")
fmt.Printf("Cache Hits: %d\n", stats.Hits)
fmt.Printf("Cache Misses: %d\n", stats.Misses)
fmt.Printf("Hit Ratio: %.2f%%\n", stats.HitRatio()*100)
fmt.Printf("Total Entries: %d\n", stats.TotalSize)
fmt.Printf("Evictions: %d\n", stats.Evictions)

fmt.Printf("\n=== Performance Improvement ===\n")
fmt.Printf("First round (cache misses): %v\n", firstRoundTime)
fmt.Printf("Second round (cache hits): %v\n", secondRoundTime)
if secondRoundTime.Nanoseconds() > 0 {
speedup := float64(firstRoundTime.Nanoseconds()) / float64(secondRoundTime.Nanoseconds())
fmt.Printf("Speedup: %.1fx faster with cache\n", speedup)
}
}

// Uncomment to run the example:
// func main() {
// ExampleCacheUsage()
// }
Loading