gomcache
is a Go library for interacting with Memcached servers using both TCP and UDP protocols. It provides a robust and simple client for performing standard Memcached operations such as setting, getting, deleting cache items, and checking server availability with high-level concurrency support.
- TCP and UDP Support: Choose between TCP or UDP protocols for communication with Memcached servers.
- Simple and Intuitive API: Easy-to-use methods for setting, getting, deleting cache items, and checking server availability with the Ping method.
- High-Level Concurrency: Thread-safe operations with built-in concurrency management for high-performance applications.
- Error Handling: Robust error handling for network and protocol errors, ensuring reliable interactions with Memcached servers.
To use gomcache
in your Go project, you need to install it using go get
. Open your terminal and run:
go get github.com/nihankhan/gomcache
Here's a quick guide on how to use the gomcache
library in your Go application:
import "github.com/nihankhan/gomcache"
Create a new Client
instance with the addresses of your Memcached servers:
client, err := gomcache.NewClient([]string{"localhost:11211"}, true) // If false disable UDP or true Enable UDP
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
Use the Set
method to add or update an item in the cache:
item := &gomcache.Item{
Key: "foo",
Value: []byte("bar"),
Flags: 0,
Expiration: 3600, // in seconds
}
err := client.Set(item)
if err != nil {
log.Fatalf("failed to set item: %v", err)
}
Use the Get
method to retrieve an item from the cache:
item, err := client.Get("foo")
if err != nil {
log.Fatalf("failed to get item: %v", err)
}
fmt.Printf("Value: %s\n", item.Value)
Use the Delete
method to remove an item from the cache:
err := client.Delete("foo")
if err != nil {
log.Fatalf("failed to delete item: %v", err)
}
Use the Ping
method to check if the server is responsive:
err := client.Ping("version\r\n")
if err != nil {
log.Fatalf("server is not responding: %v", err)
} else {
fmt.Println("Server is responsive")
}
To run tests for gomcache
, use the go test
command:
go test -v ./...
Here is the benchmark performance data for gomcache
:
Benchmark | Operations per Second | Average Latency | Memory Usage | Allocations |
---|---|---|---|---|
Single Set/Get | 12,470 | 83,486 ns/op | 96,488 B/op | 50 allocs/op |
Concurrent Set/Get (100 workers) | 1 billion | < 0.0000600 ns/op | 0 B/op | 0 allocs/op |
Contributions are welcome! If you have any ideas, improvements, or bug fixes, please open an issue or submit a pull request on the GitHub repository.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For any questions or feedback, please contact Nihan Khan.
Enjoy using gomcache
and happy coding!