Question: + ArrayCache ( ) : + ArrayCache ( sz:int ) : + put ( name:String,value:String ) :void + get ( name:String ) :String + getHits

+ArrayCache():
+ArrayCache(sz:int):
+put(name:String,value:String):void
+get(name:String):String
+getHits():int
+getMisses():int
+clear0:void
+isEmpty():boolean
+toString():String
shiftEntries(endIdx:int):void
The default constructor sets entries to an array of ten (10) CacheEntrys and numEntries,
numHits, and numMisses to zero (0).
The overloaded constructor sets entries to an array of szCacheEntrys and numEntries,
numHits, and numMisses to zero (0).
put takes a name and value (URL and IP address, respectively) and adds it to the cache.
To add an entry to the cache you should shift all cells in the array one cell to the right
(towards higher indices) and put the new entry at index zero (0). If the array is full
shifting will throw away the entry at index entries.length -1(i.e., overwrite it by shifting).
If the number of entries is less than entries.length, increment numEntries. By handling put
this way, the LRU element is always at index entries.length -1.
get takes a name (i.e., URL) and searches entries for a CacheEntry with the given name. If
found at index idx, the CacheEntry should be saved, all entries less than idx moved right
(towards higher indices), the saved entry placed at index zero(0), the numHits is
incremented, and the entry's value returned to the caller. If no entry is found, the
numMisses counter should be incremented and null should be returned.
+ ArrayCache ( ) : + ArrayCache ( sz:int ) : +

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!