Please review this implementation of thread-safe chache.
public class StaticCacheImpl<T extends Entity> implements StaticCache<T>
{
private boolean set = false;
private List<T> cachedObjects = Collections.synchronizedList(new ArrayList<T>());
@Override
public synchronized boolean isSet() {
return set;
}
@Override
public synchronized void put(List<T> cachedList) {
if (!set) {
cachedObjects.addAll(cachedList);
set = true;
}
}
@Override
public synchronized List<T> get() {
return cachedObjects;
}
@Override
public synchronized boolean contains(UUID uuid) {
if(set) {
for (T t : cachedObjects) {
if (ObjectUtils.equals(uuid, t.getId())) {
return true;
}
}
}
return false;
}
@Override
public synchronized T getById(UUID uuid) {
if(set) {
for (T t : cachedObjects) {
if (ObjectUtils.equals(uuid, t.getUuid())) {
return t;
}
}
}
return null;
}
}