Welcome to the LRU (Least Recently Used) Cache API! This project implements a simple yet efficient LRU caching mechanism with a twist - each cache item comes with an expiration time. Built with Go and the elegant Gin framework, this API provides a high-performance, concurrency-safe cache layer suitable for a wide range of applications, from optimizing backend systems to speeding up web applications.
- LRU Eviction Policy: Ensures the cache only holds the most recently accessed items, automatically evicting the least recently used ones when the cache is full.
- Expiration Time: Each key-value pair in the cache can have an expiration time, after which it gets automatically evicted, ensuring fresh data and efficient memory usage.
- High Performance: Written in Go and leveraging the Gin framework, this API is designed for speed and efficiency.
- Concurrency Safe: Uses Go's concurrency primitives to ensure that the cache is safe to use in a multi-threaded environment.
- Simple RESTful API: Provides straightforward GET and SET endpoints for easy interaction with the cache.
Dive into the world of caching with our LRU Cache API. Follow these steps to get your cache server up and running in no time!
Before you embark on this caching adventure, ensure you have the following installed on your machine:
- Go (version 1.14 or later recommended)
- A sense of adventure
-
Clone the repository
git clone https://github.com/anujaagarwal/LRU_Cache.git cd LRU_Cache
-
Run the server
Fire up your terminal and launch the cache into action:
go run main.go
Your LRU Cache API is now listening for cache interactions!
Interact with the cache using its RESTful endpoints:
-
Set a key-value pair
GET /set?key=<your-key>&value=<your-value>&duration=<expiration-in-seconds>
Set your desired key-value pair in the cache, along with an optional expiration duration in seconds.
-
Get a value by key
GET /get?key=<your-key>
Retrieve the value associated with your specified key. Remember, if the key has expired or doesn't exist, you'll embark on a quest to find nothing.
Setting a key-value pair with a 60-second expiration:
curl "http://localhost:8080/set?key=hero&value=batman&duration=60s"
Retrieving the value for the key hero
:
curl "http://localhost:8080/get?key=hero"
Join the cache crusade! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Embark on this caching journey and unlock the potential of efficient data retrieval. Should you have any queries or require assistance, feel free to raise an issue in the repository. Happy caching! ๐