Back to project page Dumbledroid.
The source code is released under:
Copyright (c) 2013, Leocadio Tin? All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...
If you think the Android project Dumbledroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package io.leocad.dumbledroid.data.cache; /* w w w. j a v a 2 s .c om*/ import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Map; public class MemoryCache { private static final MemoryCache INSTANCE = new MemoryCache(); public static MemoryCache getInstance() { return INSTANCE; } private Map<String, SoftReference<ModelHolder>> mMap; private MemoryCache() { mMap = new HashMap<String, SoftReference<ModelHolder>>(); } public void cache(String key, ModelHolder holder) { final SoftReference<ModelHolder> ref = new SoftReference<ModelHolder>(holder); mMap.put(key, ref); } public ModelHolder getCached(String key) { final SoftReference<ModelHolder> reference = mMap.get(key); if (reference == null) { return null; } final ModelHolder holder = reference.get(); if(holder == null) { reference.clear(); mMap.remove(key); } return holder; } }