Skip to content

ItzXitado/Cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

App Screenshot

Cache

Its a Java framework that handles data in the memory.

Features

  • Individual expiration time

Future features

  • Events and Listeners
  • Better handling complexity

Code

App Screenshot The Builder class, used to instance the framework and build a cache.

Usage Example

public class CacheExample {

    public static void main(String[] args) {
        // Create a cache with an expiration time of 5 seconds (5000 milliseconds)
        MemoryCache<String, String> cache = new CacheBuilder<String, String>()
                .expirationTime(5000)
                .build();

        // Add an entry to the cache
        cache.put("key1", "value1");

        // Retrieve the entry from the cache
        try {
            String value = cache.get("key1");
            System.out.println("Retrieved value: " + value);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        // Wait for 6 seconds to allow the entry to expire
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // Try to retrieve the entry again after expiration
        try {
            String value = cache.get("key1");
            System.out.println("Retrieved value: " + value);
        } catch (Exception e) {
            System.out.println(e.getMessage()); // Expected to catch an exception since the entry has expired
        }
    }
}

About

A project made just for experience. The objective is to keep it simple

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published