Skip to content

A flexible, lightweight, and thread-safe in-memory caching library for microservices and small-scale applications. Supports time-based expiration, size-based eviction, and can cache any type of object including lists, maps, and custom data structures. Ideal for quick caching needs in distributed services.

License

Notifications You must be signed in to change notification settings

adityasingh9699/lightweight-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Light-weight Cache

Overview

The light-weight cache is an in-memory caching solution designed for microservices. It supports:

  • Flexible data storage - store any type of object, including lists, maps and custom data structures.
  • Time-based expiry - automatically removes stale cache entries after a configurable duration.
  • Size-based eviction - maintains a maximum number of entries, using Least Recently Used (LRU) eviction.
  • Thread safety - ensures safe access to cache in multi-threaded environment.

Features

  • ✅ Simple API: put(), get(), remove() methods
  • 🕒 Configurable expiration time
  • 📏 Max size limits with automatic eviction
  • 🔒 Thread-safe operations
  • 🔄 Supports storing collections & complex objects

Usage

  • Creating a Cache Instance

    FlexibleCache<List<String>> cache = new FlexibleCache<>(5, TimeUnit.MINUTES, 100);

    First Parameter: Expiration time (e.g., 5 MINUTES)

    Second Parameter: Maximum cache size before eviction occurs (e.g., 100 items)

  • Adding Data to Cache

    cache.put("fruits", List.of("Apple", "Banana", "Mango"));

  • Retrieving Data

    Optional<List<String>> cachedFruits = cache.get("fruits");

    System.out.println(cachedFruits.orElse(Collections.emptyList()));

  • Expiry & Eviction Behavior

    Thread.sleep(6000); // Simulate delay (6 sec)

    System.out.println(cache.get("fruits")); // Expected: Empty (Expired!)

📜 License

This project is licensed under the MIT License.

📬 Contact

If you have any questions or issues, feel free to reach out!

About

A flexible, lightweight, and thread-safe in-memory caching library for microservices and small-scale applications. Supports time-based expiration, size-based eviction, and can cache any type of object including lists, maps, and custom data structures. Ideal for quick caching needs in distributed services.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published