Android Open Source - WebImageView Base Mem Cache






From Project

Back to project page WebImageView.

License

The source code is released under:

MIT License

If you think the Android project WebImageView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rsv.cache;
//from w w w .  j ava 2s.c  o  m
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

abstract class BaseMemCache<K, V> {

  protected final Map<K, Reference<V>> cacheMap = Collections
      .synchronizedMap(new LinkedHashMap<K, Reference<V>>());

  public V get(K key) {
    V result = null;
    Reference<V> reference = cacheMap.get(key);
    if (reference != null) {
      result = reference.get();
    }
    return result;
  }

  public boolean put(K key, V value) {
    cacheMap.put(key, createReference(value));
    return true;
  }

  public boolean exists(K key) {
    return this.get(key) != null;
  }

  public void remove(K key) {
    cacheMap.remove(key);
  }

  public void removeFirst() {

    if (cacheMap.size() == 0)
      return;

    K fkey = cacheMap.keySet().iterator().next();
    this.remove(fkey);
  }

  public void removeLast() {

    if (cacheMap.size() == 0)
      return;

    K lkey = null;

    for (K key : cacheMap.keySet()) {
      lkey = key;
    }

    this.remove(lkey);
  }

  public int size() {
    return cacheMap.size();
  }

  public Collection<K> keys() {
    return cacheMap.keySet();
  }

  public void clear() {
    cacheMap.clear();
  }

  protected Reference<V> createReference(V value) {
    return new WeakReference<V>(value);
  }
}




Java Source Code List

com.rsv.cache.BaseFileCache.java
com.rsv.cache.BaseMemCache.java
com.rsv.cache.LmtSizeMemCache.java
com.rsv.cache.LmtSpaceFileCache.java
com.rsv.comp.IProgressListener.java
com.rsv.comp.ImageLoader.java
com.rsv.config.ConfigReader.java
com.rsv.config.Constants.java
com.rsv.utils.FileUtils.java
com.rsv.utils.HttpClientUtils.java
com.rsv.utils.IOUtils.java
com.rsv.utils.ImgUtils.java
com.rsv.utils.LogUtils.java
com.rsv.utils.OSUtils.java
com.rsv.utils.StorageUtils.java
com.rsv.widget.WebImageView.java