?? replacecomputingfifo.java
字號:
//Source file: E:/工作和學習/工作/碩士論文工作/程序/數據庫緩存管理/20040304/src/MemCachePak/ReplaceComputingFIFO.java
package MemCachePak;
public class ReplaceComputingFIFO implements ReplaceComInterface
{
public MemCacheInterface theCache;
public ReplaceComputingFIFO()
{
}
/**
@roseuid 41C63F60032C
*/
public ReplaceComputingFIFO(MemCacheInterface Cache)
{
theCache = Cache;
}
/**
@roseuid 41C63FBB0157
*/
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 41C63FBB01B5
*/
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 41C63FBB0242
*/
public boolean ReplaceCache()
{
//FIFO算法的具體策略在這里實現
//首先判斷緩存大小是否超過了門限
//如果超過了門限,則執行替換算法,返回true
if(theCache.GetCacheSize()>=Configuration.MAX_SIZE)
{
System.out.println("緩存進行了一次替換FIFO");
//theCache.Print();
WebObj headObj,NowObj,FIFOObj;
FIFOObj = null;
headObj = theCache.GetTheFirstObj();
long TimeNow=System.currentTimeMillis();
long FET = TimeNow;
while(headObj!=null)
{
NowObj = headObj;
while(NowObj!=null)
{
long FirstEnterTime = 0;
FirstEnterTime=NowObj.GetEnterTime();
//判斷
if(FirstEnterTime<FET)
{
FET = FirstEnterTime;
FIFOObj = NowObj;
}
//轉到下一個版本對象
NowObj = NowObj.NextObjEdition;
}
//轉到下一個版本對象群
headObj = headObj.NextObj;
}
if(FIFOObj!=null)
{
//theCache.Print();
theCache.DeleteObj(FIFOObj);
//同步刪除文件
}
//theCache.Print();
return true;
}
else
{
//如果沒有超過門限,則不執行替換算法,返回false
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -