com.javonet.core.handler.ReferencesCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javonet-java-sdk Show documentation
Show all versions of javonet-java-sdk Show documentation
Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology.
It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products.
Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today!
For more information check out our guides at https://www.javonet.com/guides/v2/
package com.javonet.core.handler;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ReferencesCache {
private static final Map REFERENCES_CACHE = new HashMap<>();
private static ReferencesCache instance;
private ReferencesCache() {
}
public static ReferencesCache getInstance() {
if (instance == null) {
instance = new ReferencesCache();
}
return instance;
}
public String cacheReference(Object reference) {
UUID uuid = UUID.randomUUID();
String uuidString = uuid.toString();
REFERENCES_CACHE.putIfAbsent(uuidString, reference);
return uuidString;
}
public static boolean deleteReference(String uuidString){
Object result = REFERENCES_CACHE.remove(uuidString);
return result == null;
}
public Object resolveReference(String uuidString) {
return REFERENCES_CACHE.get(uuidString);
}
}