{"id":27020075,"url":"https://github.com/jeffotoni/gocache","last_synced_at":"2025-04-04T18:21:42.925Z","repository":{"id":168486460,"uuid":"644201162","full_name":"jeffotoni/gocache","owner":"jeffotoni","description":"GoCache – High-Performance In-Memory Cache for Go","archived":false,"fork":false,"pushed_at":"2025-02-28T06:45:17.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T13:47:54.633Z","etag":null,"topics":["cache-memory","go","gocache","golang","memory"],"latest_commit_sha":null,"homepage":"https://goquick.run","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-23T03:09:43.000Z","updated_at":"2025-02-28T06:45:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"e02b31aa-9023-4fa3-93a9-dec6f83d6138","html_url":"https://github.com/jeffotoni/gocache","commit_stats":null,"previous_names":["jeffotoni/gcache","jeffotoni/gocache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgocache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgocache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgocache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgocache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/gocache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226308,"owners_count":20904487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache-memory","go","gocache","golang","memory"],"created_at":"2025-04-04T18:21:42.408Z","updated_at":"2025-04-04T18:21:42.915Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","readme":"# ⚡ gocache – High-Performance \n\n[![GoDoc](https://godoc.org/github.com/jeffotoni/gocache?status.svg)](https://godoc.org/github.com/jeffotoni/gocache) [![Go Report](https://goreportcard.com/badge/github.com/jeffotoni/gocache)](https://goreportcard.com/report/github.com/jeffotoni/gocache) [![License](https://img.shields.io/github/license/jeffotoni/gocache)](https://github.com/jeffotoni/gocache/blob/main/LICENSE) ![GitHub last commit](https://img.shields.io/github/last-commit/jeffotoni/gocache) ![GitHub contributors](https://img.shields.io/github/contributors/jeffotoni/gocache)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/jeffotoni/gocache/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/jeffotoni/gocache/tree/main)\n[![Coverage Status](https://coveralls.io/repos/github/jeffotoni/gocache/badge.svg)](https://coveralls.io/github/jeffotoni/gocache)\n![GitHub stars](https://img.shields.io/github/forks/jeffotoni/gocache?style=social) \n![GitHub stars](https://img.shields.io/github/stars/jeffotoni/gocache)\n\n---\n\n## 🚀 About gocache\n\n**GoCache** is a high-performance, **sharded** in-memory cache for Go applications, built for **speed and efficiency**. This implementation is **optimized for concurrent read/write operations**, leveraging **sharding, lock optimizations, and expiration management** to outperform other Go-based caches.\n\n## 🔥 **Why use gocache?**  \n✅ **Ultra-fast read \u0026 write operations**  \n✅ **Sharded architecture for minimal lock contention**  \n✅ **Automatic expiration \u0026 cleanup of stale data**  \n✅ **Simple API with support for TTL (Time-To-Live)**  \n✅ **Benchmarked \u0026 optimized for real-world workloads**\n\n---\n\n## 📦 Installation\n\n```sh\n$ go get github.com/jeffotoni/gocache\n```\n## 🔥 Quick Start\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/jeffotoni/gocache\"\n)\n\nfunc main() {\n\t// Create cache with a 10-minute TTL\n\tcache := gocache.New(10 * time.Minute)\n\t\n\t// Store items in cache\n\tcache.Set(\"key1\", \"Hello, gocache!\", gocache.DefaultExpiration)\n\tcache.Set(\"key2\", 12345, gocache.DefaultExpiration)\n\t\n\tvar myPerson = struct {\n\t\tID int\n\t\tName   string\n\t}{\n\t\tID: 564,\n\t\tName:   \"@jeffotoni\",\n\t}\n\tcache.Set(\"key3\", myPerson, gocache.DefaultExpiration)\n\t\n\t// Retrieve items\n\tval, found := cache.Get(\"key1\")\n\tif found {\n\t\tfmt.Println(\"Found key1:\", val)\n\t}\n\n\tval, found = cache.Get(\"key2\")\n\tif found {\n\t\tfmt.Println(\"Found key2:\", val)\n\t}\n\t\n\tval, found = cache.Get(\"key3\")\n\tif found {\n\t\tfmt.Println(\"Found key3:\", val)\n\t}\n\t\n\t// Deleting an item\n\tcache.Delete(\"key1\")\n\n\t// Attempting to retrieve deleted item\n\tval, found = cache.Get(\"key1\")\n\tif !found {\n\t\tfmt.Println(\"key1 not found in cache\")\n\t}\n}\n```\n\n## ⚡ Benchmark Results\n\n### 🚀 1-Second Benchmarks\n\n```go\n$ go test -bench=. -benchtime=1s\n```\n\n| **Implementation** | **Set Ops**    | **Set ns/op** | **Set/Get Ops** | **Set/Get ns/op** | **Observations**                      |\n|--------------------|----------------|---------------|-----------------|-------------------|---------------------------------------|\n| **gocache V7**     | 8,026,825      | 222.4 ns/op   | 4,978,083       | 244.3 ns/op       | 🏆 **Best write** (1s), fast reads    |\n| **gocache V9**     | 9,295,434      | 215.9 ns/op   | 5,096,511       | 272.7 ns/op       | 🏆 **Fastest write** (lowest ns/op)   |\n| **go-cache**       | 6,463,236      | 291.6 ns/op   | 4,698,109       | 290.7 ns/op       | Solid library, slower than V7/V9      |\n| **freecache**      | 5,803,242      | 351.1 ns/op   | 2,183,834       | 469.7 ns/op       | 🚀 Decent writes, poor reads          |\n\n### 🚀 3-Second Benchmarks\n\n| **Implementation** | **Set Ops**     | **Set ns/op** | **Get Ops**     | **Get ns/op** | **Observations**                     |\n|--------------------|-----------------|---------------|-----------------|---------------|--------------------------------------|\n| **gocache V7**     | 27,229,544      | 252.4 ns/op   | 14,574,768      | 268.6 ns/op   | 🏆 **Best write** (3s)               |\n| **gocache V9**     | 24,809,947      | 252.1 ns/op   | 13,225,228      | 275.7 ns/op   | 🏆 **Very fast write**, good read    |\n| **go-cache**       | 15,594,752      | 375.4 ns/op   | 14,289,182      | 269.7 ns/op   | 🚀 Excellent reads, slower writes    |\n| **freecache**      | 13,303,050      | 402.3 ns/op   | 8,903,779       | 421.4 ns/op   | ❌ Decent write, slow read           |\n\n#### 🚀 You can find all the benchmarks here [benchmark-gocache](https://github.com/jeffotoni/benchmark-gocache)\n\n# 🛠 API Reference\n\nNew Cache\n```go\ncache := gocache.New(10 * time.Minute) // Creates a cache with 10 min TTL\n```\n\nSet Value\n```go\ncache.Set(\"key\", \"value\", gocache.DefaultExpiration)\n```\n\nGet Value\n```go\nval, found := cache.Get(\"key\")\n```\n\nDelete Value\n```go\ncache.Delete(\"key\")\n```\n\n## ⚖️ Trade-Offs \u0026 Performance\n\n✅ V7 and V9 provide the fastest write performance.\n\n✅ go-cache excel in retrieval speed.\n\n❌ FreeCache struggles with read speed, despite having decent write speed.\n\n## 🤝 Contributing\n\n**🚀 Want to improve gocache? Follow these simple steps:**\n\n 1️⃣ Fork this repo and add your own cache optimizations.\n\n 2️⃣ Submit a Pull Request (PR) with your improvements.\n\n 3️⃣ Open an issue if you have questions or ideas for enhancements.\n\n**Your contributions are always welcome! 💡🔥**\n\n## 📜 License\n\nThis project is **open-source** under the **MIT License**.\n\n💡 Feel free to **fork, modify, and experiment** with these benchmarks in your own applications or libraries.  \n🔬 The goal is to **help developers choose the best in-memory cache** for their needs.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgocache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fgocache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgocache/lists"}