I would like to implement a common cache variable storage in order to share between classes. I have many classes because I use cucumber java webdriver and it is necessary to share between steps, page objects/classes.
I have the class
public class Cache {
private HashMap<String, String> cache = new HashMap<String, String>();
public HashMap<String, String> getCache() {
return cache;
}
}
But the question, what is the most efficient way to set the key-value pairs?
My idea would be use a getter to get and use the stored variables such as cache.get("KEY") and I get the value. How to store variables in efficient way in this cache?
Any example code would be appreciated.