通用大型网站页面静态化解决方案

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了通用大型网站页面静态化解决方案脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
多个文件服务器读写,这里可采用SMB协议
页面静态化,可采用freemarker开框架
如果考虑到大量的读写请求,则将请求分布式或采用调度的办法来解决
一点我们首先应该考虑文件服务器与静态页面的映射关系,即什么文件应该读写到哪台服务器,这个关系最简单的办法是随机映射,然后将映射关系保存到数据库中即可,SMB常用的操作代码如下:
复制代码 代码如下:

    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();
}

第二点,页面静态化可由freemarker生成,freemarker的使用比较简单,我这里不再啰嗦,重复说了
第三点,调度中心,或把静态化的请求先保存到Task中,然后通过调度中心异步执行,可用我在博客中说道的另外一篇文章解决即可

脚本宝典总结

以上是脚本宝典为你收集整理的通用大型网站页面静态化解决方案全部内容,希望文章能够帮你解决通用大型网站页面静态化解决方案所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。