{"id":17586832,"url":"https://github.com/ndeta100/mcache","last_synced_at":"2026-05-05T05:35:35.848Z","repository":{"id":258268569,"uuid":"867577714","full_name":"Ndeta100/mcache","owner":"Ndeta100","description":"Personal memory cache for my Hotel management system, small alternative to redis, still building","archived":false,"fork":false,"pushed_at":"2024-10-17T22:37:24.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T11:04:49.077Z","etag":null,"topics":["golang","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ndeta100.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-10-04T10:26:19.000Z","updated_at":"2024-10-17T22:37:28.000Z","dependencies_parsed_at":"2024-10-18T08:15:27.124Z","dependency_job_id":null,"html_url":"https://github.com/Ndeta100/mcache","commit_stats":null,"previous_names":["ndeta100/mcache"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ndeta100%2Fmcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ndeta100%2Fmcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ndeta100%2Fmcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ndeta100%2Fmcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ndeta100","download_url":"https://codeload.github.com/Ndeta100/mcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246223268,"owners_count":20743158,"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":["golang","yaml"],"created_at":"2024-10-22T03:06:29.857Z","updated_at":"2026-05-05T05:35:35.818Z","avatar_url":"https://github.com/Ndeta100.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Cache Server\n\nA simple TCP server in Go for managing a key-value cache. This project includes:\n\n- A TCP server that allows clients to interact with the cache over a telnet connection.\n- A cache with configurable capacity, TTL, and snapshot persistence using `.gob`.\n- Graceful shutdown for managing connections and ensuring data integrity.\n\n## Features\n\n- **Key-Value Cache**: Supports `GET`, `SET`, and `DELETE` commands.\n- **Persistence**: Cache is saved to disk as a snapshot using Go's `gob` encoding.\n- **Eviction**: Items automatically expire based on TTL and are periodically evicted.\n- **Graceful Shutdown**: Handles termination signals to close connections and save the cache.\n- **Thread Safety**: Uses mutex locks to ensure safe concurrent access to the cache.\n\n## Installation\n\n### Prerequisites\n\n- Go 1.16 or higher\n\n### Setup\n\n1. Clone the repository:\n\n   ```sh\n   git clone https://github.com/Ndeta100/mcache.git\n   go get go get github.com/Ndeta100/mcache@v1.0.1  # or v1.1.0\n   cd mcache\n   ```\n\n2. Install dependencies:\n\n   ```sh\n   go mod tidy\n   ```\n\n3. Build the server:\n\n   ```sh\n   go build -o cache-server\n   ```\n\n## Usage\n\n### Starting the Server\n\nRun the server executable:\n\n```sh\n./mcache\n```\n\nBy default, the server listens on `localhost:6379`. You can modify the configuration (`config/config.yaml`) to change the listening address and port.\n\n### Connecting to the Server\n\nYou can use a telnet client to connect to the server:\n\n```sh\ntelnet localhost 6379\n```\n\n### Commands\n\n- **SET**: Set a key-value pair in the cache.\n\n  ```sh\n  SET key value\n  OK\n  ```\n\n- **GET**: Retrieve a value by key.\n\n  ```sh\n  GET key\n  VALUE: value\n  ```\n\n- **DELETE**: Delete a key from the cache.\n\n  ```sh\n  DELETE key\n  OK\n  ```\n\n- **Graceful Shutdown**: Press `CTRL+C` to stop the server. All active connections will be closed, and the cache state will be saved to disk.\n\n## Configuration\n\nThe server configuration is defined in `config/config.yaml`. You can set options like:\n\n- `host`: The server's hostname or IP.\n- `port`: The server's port number.\n- `capacity`: The maximum number of items allowed in the cache.\n- `ttl`: The time-to-live for cache entries, in seconds.\n\n## Graceful Shutdown\n\nThe server supports graceful shutdown, allowing it to:\n\n- Stop accepting new connections.\n- Close all active connections.\n- Save the current cache state to disk.\n\nThis is triggered when the server receives a termination signal (`SIGINT` or `SIGTERM`).\n\n## Development\n\n### Running Tests\n\nYou can run unit tests for the cache and server:\n\n```sh\ngo test ./...\n```\n\n### Code Structure\n\n- **`server`**: Contains the TCP server code.\n- **`store`**: Implements the key-value cache with persistence and TTL.\n- **`handler`**: Handles client commands (`GET`, `SET`, `DELETE`).\n- **`config`**: Contains configuration utilities.\n\n## Improvements to Consider\n\n- **Logging**: Improve logging for better observability of server events.\n- **Authentication**: Add authentication to limit access to the cache.\n- **REST API**: Implement a RESTful API for more accessible programmatic interaction.\n- **Optimized Persistence**: Implement incremental snapshots or append-only logs for more efficient persistence.\n\n## Contributing\n\nPull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndeta100%2Fmcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndeta100%2Fmcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndeta100%2Fmcache/lists"}