Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.internal;
 
 
A bounded cache that has a FIFO eviction policy when the cache is full.

Parameters:
<T> value type
 
 public final class FIFOCache<T> {
     private final BoundedLinkedHashMap<String, T> map;
     private final ReadLock rlock;
     private final WriteLock wlock;

    

Parameters:
maxSize the maximum number of entries of the cache
 
     public FIFOCache(final int maxSize) {
         if (maxSize < 1) {
             throw new IllegalArgumentException("maxSize " + maxSize
                     + " must be at least 1");
         }
          = new BoundedLinkedHashMap<String, T>(maxSize);
         ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
          = lock.readLock();
          = lock.writeLock();
     }

    
Adds an entry to the cache, evicting the earliest entry if necessary.
 
     public T add(String key, T value) {
         .lock();
         try {
             return .put(keyvalue);
         } finally {
             .unlock();
         }
     }

    
Returns the value of the given key; or null of no such entry exists.
 
     public T get(String key) {
         .lock();
         try {
             return .get(key);
         } finally {
             .unlock();
         }
     }

    
Returns the current size of the cache.
 
     public int size() {
         .lock();
         try {
             return .size();
         } finally {
             .unlock();
         }
     }

    
Returns the maximum size of the cache.
 
     public int getMaxSize() {
         return .getMaxSize();
     }
 
     @Override
     public String toString() {
         .lock();
         try {
             return .toString();
         } finally {
             .unlock();
         }
     }
New to GrepCode? Check out our FAQ X