中文 | English
APK Cache is a high-performance proxy server for caching Alpine Linux APK packages and Debian/Ubuntu APT packages. It features a three-tier caching architecture (Memory → File → Upstream), health monitoring with self-healing capabilities, and comprehensive security features.
apk-cache/
├── cmd/
│ ├── apk-cache/ # Main application
│ │ ├── main.go # Entry point
│ │ ├── config.go # Configuration loading
│ │ ├── cache.go # File cache implementation
│ │ ├── memory_cache.go # In-memory cache layer
│ │ ├── handlers.go # HTTP request handlers
│ │ ├── admin.go # Admin dashboard
│ │ ├── upstream.go # Upstream server management
│ │ ├── cleanup.go # Cache cleanup logic
│ │ ├── cache_quota.go # Cache quota management
│ │ ├── cache_apt.go # APT proxy support
│ │ ├── http_proxy.go # HTTP proxy support
│ │ └── access_tracker.go # Access tracking
│ └── apt-hash/ # APT hash tool
├── build.sh # Build script (required)
├── Dockerfile # Docker build file
├── go.mod # Go module definition
├── go.sum # Go dependencies
├── config.example.toml # Configuration example
└── cmd/apk-cache/admin.html # Admin dashboard HTML
- Go 1.25 or later
- Git
- For HTML compression (optional): html-minifier, python-htmlmin, or esbuild
Important: Always use the build script, not go build directly:
./build.shThe build script automatically:
- Detects available HTML compression tools
- Compresses the admin dashboard HTML
- Creates gzip-compressed versions
- Builds the Go application with optimizations
# Default configuration
./apk-cache
# With custom config
./apk-cache -config config.toml
# With command-line arguments
./apk-cache -addr :3142 -cache ./cache -proxy socks5://127.0.0.1:1080- Docker installed and running
The project includes an integration test script that tests both APK and APT caching functionality:
./run_test.shThe test script performs the following steps:
- Build the application using
build.sh(called automatically during Docker build) - Build Docker image
- Start the apk-cache service
- Test with Alpine Linux client (apk update)
- Test with Debian client (apt-get update)
The script automatically cleans up the test environment (containers, images) after tests complete, but preserves the cache directory (/tmp/apk-cache-test-cache) for inspection.
| Parameter | Description |
|---|---|
--goproxy <value> |
Set GOPROXY for go build dependencies |
--alpine-apk-mirror <url> |
Alpine mirror for Docker build (e.g., http://mirror/alpine) |
--apk-mirror <url> |
Alias for --alpine-apk-mirror |
--lang <zh|en> |
Set language (default: auto-detect) |
-h, --help |
Show help message |
# Run tests with Chinese output
./run_test.sh --lang zh
# Run tests with a custom Go proxy
./run_test.sh --goproxy https://goproxy.cn
# Run tests with a custom Alpine mirror
./run_test.sh --alpine-apk-mirror http://mirror.example.com/alpine- Use camelCase for variable and function names
- Use PascalCase for exported types, functions, and constants
- Use mixedCaps for unexported global variables
- Always handle errors explicitly
- Return errors instead of logging silently when appropriate
- Use
fmt.Errorf("context: %v", err)for error messages - Use
errors.New()for static error messages
- Use structured logging with appropriate levels
- Include context in log messages
- All user-facing strings must use the i18n system via
i18n.T() - Never hardcode visible strings - use translation keys
- Provide translation keys in
utils/i18n/directory
- All configuration options must have CLI flags
- Configuration can also be loaded from TOML files
- Use sensible defaults with clear documentation
- Memory Cache: LRU cache with TTL support, fastest access
- File Cache: Persistent disk storage
- Upstream: Original package sources
- Periodic checks for upstream servers, filesystem, memory cache, and cache quota
- Automatic failover to healthy upstreams
- Self-healing mechanisms for common issues
- Proxy authentication (SOCKS5/HTTP)
- Admin dashboard authentication
- IP whitelisting
- Reverse proxy support
- Path security validation
- Create a new branch:
git checkout -b feature/your-feature - Make changes following code conventions
- Add tests for new functionality
- Update documentation
- Submit pull request
Core dependencies (see go.mod):
github.com/prometheus/client_golang- Prometheus metricsgo.etcd.io/bbolt- Embedded databasegolang.org/x/net- HTTP utilitiesgithub.com/nicksnyder/go-i18n/v2- Internationalization