?? replacecomputinglru.java
字號:
//Source file: E:/工作和學習/工作/碩士論文工作/程序/數據庫緩存管理/20040304/src/MemCachePak/ReplaceComputingLRU.java
package MemCachePak;
public class ReplaceComputingLRU implements ReplaceComInterface
{
public MemCacheInterface theCache;
public ReplaceComputingLRU()
{
}
/**
@roseuid 41C63B8A02CE
*/
public boolean InsertNewObj(String[] RefArray, int ObjSize, int TimeCost)
{
WebObj obj = new WebObj();
obj.SetSourceFileName(RefArray[0]);
obj.SetCachedFileName(RefArray[1]);
obj.SetObjRef(RefArray);
obj.SetCost(TimeCost);
obj.SetFileSize(ObjSize);
obj.SetEnterTime();
theCache.InsertNewObj(obj);
theCache.InsertNewVector(TimeCost,RefArray[0],RefArray[1],RefArray[0]);
return true;
}
/**
@roseuid 41C63CBA0128
*/
public boolean InsertNewObj(String[] RefArray, int ObjSize, int TimeCost, String BeginPoint, boolean SourceOrMedia)
{
WebObj obj = new WebObj();
obj.SetSourceFileName(RefArray[0]);
obj.SetCachedFileName(RefArray[1]);
obj.SetObjRef(RefArray);
obj.SetCost(TimeCost);
obj.SetFileSize(ObjSize);
obj.SetEnterTime();
theCache.InsertNewObj(obj);
if(SourceOrMedia)
{
theCache.InsertNewVector(TimeCost,RefArray[0],RefArray[1],RefArray[0]);
}
else
{
WebObj MediaObj = theCache.GetCachedObj(RefArray[0],BeginPoint);
if(MediaObj!=null)
{
MediaObj.AddMediaUsedCount();
MediaObj.SetLastMediaUsedTime();
}
theCache.InsertNewVector(TimeCost,BeginPoint,RefArray[1],RefArray[0]);
}
return true;
}
/**
@roseuid 41C63D2900CB
*/
public boolean ReplaceCache()
{
//LRU算法的具體策略在這里實現
//首先判斷緩存大小是否超過了門限
//如果超過了門限,則執行替換算法,返回true
if(theCache.GetCacheSize()>=Configuration.MAX_SIZE)
{
System.out.println("緩存進行了一次替換LRU");
//theCache.Print();
WebObj headObj,NowObj,LRUObj;
LRUObj = null;
headObj = theCache.GetTheFirstObj();
long TimeNow=System.currentTimeMillis();
long LRU = TimeNow;
while(headObj!=null)
{
NowObj = headObj;
while(NowObj!=null)
{
long lastusedtime = 0;
lastusedtime=NowObj.GetLastUsedTime(1);
//判斷
if(lastusedtime<LRU)
{
LRU = lastusedtime;
LRUObj = NowObj;
}
//轉到下一個版本對象
NowObj = NowObj.NextObjEdition;
}
//轉到下一個版本對象群
headObj = headObj.NextObj;
}
if(LRUObj!=null)
{
//theCache.Print();
theCache.DeleteObj(LRUObj);
//同步刪除文件
}
//theCache.Print();
return true;
}
else
{
//如果沒有超過門限,則不執行替換算法,返回false
return false;
}
}
/**
@roseuid 41C63EA501E4
*/
protected ReplaceComputingLRU(MemCacheInterface Cache)
{
theCache = Cache;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -