欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通用大型網(wǎng)站頁面靜態(tài)化解決方案

 更新時(shí)間:2008年10月16日 23:47:38   作者:  
在開發(fā)大型網(wǎng)站時(shí),避免不了處理大量的頁面靜態(tài)化操作,這樣方便加快網(wǎng)站訪問速度與流量分流,那么如何來實(shí)現(xiàn)呢?其實(shí)說白了比較簡單,網(wǎng)站靜態(tài)化主要包括以下幾方面的工作
多個(gè)文件服務(wù)器讀寫,這里可采用SMB協(xié)議
頁面靜態(tài)化,可采用freemarker開源框架
如果考慮到大量的讀寫請(qǐng)求,則將請(qǐng)求分布式或采用調(diào)度的辦法來解決
第一點(diǎn)我們首先應(yīng)該考慮文件服務(wù)器與靜態(tài)頁面的映射關(guān)系,即什么文件應(yīng)該讀寫到哪臺(tái)服務(wù)器,這個(gè)關(guān)系最簡單的辦法是隨機(jī)映射,然后將映射關(guān)系保存到數(shù)據(jù)庫中即可,SMB常用的操作代碼如下:
復(fù)制代碼 代碼如下:

    public static boolean exists(String filepath,String username,String pwd) throws Exception
    {
    SmbFile file = new SmbFile("smb://"+username+":"+pwd+"@"+filepath);
try{
    return file.exists();
}catch(Exception ex){
    return false;
}
    }

public static boolean fileRename(String filepath,String newFilename,String username,String pwd)
    {
    try{
         SmbFile f=new SmbFile("smb://"+username+":"+pwd+"@"+filepath);
         if(f.isFile()){
     String str=filepath.substring(0,filepath.lastIndexOf("/"));
     str="smb://"+username+":"+pwd+"@"+str+"/"+newFilename;
     f.renameTo(new SmbFile(str));
         }else if(f.isDirectory()){
         String str=filepath.substring(0,filepath.length()-1);
         str=filepath.substring(0,str.lastIndexOf("/"));
         str="smb://"+username+":"+pwd+"@"+str+"/"+newFilename;
         f.renameTo(new SmbFile(str));              
         }
     return true;
    }catch(Exception ex){
        return false;
    }
    }

public static void mkdir(String dir,String username,String pwd)
{
try{
     SmbFile f=new SmbFile("smb://"+username+":"+pwd+"@"+dir);
     if(!f.exists())
f.mkdir();
}catch(Exception ex)
{
}
}

public static void mkfile(String filepath,String username,String pwd)
{
try
{
     SmbFile f=new SmbFile("smb://"+username+":"+pwd+"@"+filepath);
     if(!f.exists())
f.createNewFile();
}catch(Exception ex)
{
}
}

public static void mkfile(String filepath,String username,String pwd,String content)
{
try
{
     SmbFile f=new SmbFile("smb://"+username+":"+pwd+"@"+filepath);
     if(!f.exists())
f.createNewFile();
writeFile(filepath,content,username,pwd);
}catch(Exception ex)
{
}
}

public static boolean isdir(String filepath,String username,String pwd) throws Exception
{
String dir="smb://"+username+":"+pwd+"@"+filepath;
SmbFile f=new SmbFile(dir);
return f.isDirectory();
}

第二點(diǎn),頁面靜態(tài)化可由freemarker生成,freemarker的使用比較簡單,我這里不再啰嗦,重復(fù)說了
第三點(diǎn),調(diào)度中心,或把靜態(tài)化的請(qǐng)求先保存到Task中,然后通過調(diào)度中心異步執(zhí)行,可用我在博客中說道的另外一篇文章解決即可

相關(guān)文章

最新評(píng)論