日期:2011-12-07  浏览次数:20941 次

对<<在ASP中改善动态分页的性能>>的不足与修正建议

呵呵,可以进精华区吗?用了我一天的时间。
两位张兄的<<在ASP中改善动态分页的性能>>一文给我很大的启发,在此表示感谢,但在我想来还是有一些不足的地方。

一是无法反应一些随更新的信息。
    加设现为一BBS,那么随时更新的信息有
    每个贴子的点击
    新加贴子的信息,这些在两位张兄兄的方案中无法自动更新,只有用户在更改查询时才能使用。

二是内存使用太多,事实上对于一个论坛来讲,大多数人还是按顺序来访问的,没有必要每个人一个session。

三是处理数据时不方便
  只能用数组的方式来进行,不直观,可读性差。


对于以上几点,我提出如下改进方案
一 使用application, 可做到多人共同使用同一数据
二 只存入和取出ID号,其它数据做第二次select
三 自动删除过时的application 以节约内存.
四 在添加和删除数据时,重新导入数据

其它好处
呵呵,可以使用getstring()了,原来分页时不行的
可以不用1,3了,

代码如下

a_page.asp
-----------------------------------------------------------------'
<%
dim apage_pagesize    '每页记录数
dim apage_Count        '总计记录数
dim apage_PageCount    '总页数
dim apage_PageForm    '跳页用的Form
dim apage_PageUrl    '上一页下一页的链接
dim apage_timeout    '过期时间设置(秒)

apage_timeout=300    '过期时间设置(秒)
apage_pagesize=20    '

function apage_bactive (str_name)    '判断是否有这个对象,并删除过期对象
    apage_bactive=false
    dim item, s_temp
    for item=1 to Application.contents.count '找出所有的Application
        s_temp=Application.contents(item)
        if isarray (s_temp) then
            if ubound(s_temp)=3 and s_temp(0)="apage" then
                if s_temp(1)=str_name then
                    apage_bactive=true                '要求对象存在
                else
                    if DateDiff("s",s_temp(2),now())>apage_timeout then '删除过其对象
                        Application.contents.remove(item)
                    end if
                end if
            end if
        end if
    next
end function  'b_inuser

sub apage_open (str_name , str_table, str_id, str_sqlend)    '打开对象并计算一些数据
        '对象名,    表名,     关键字名, 查询条件
    dim a1, a_ob
    if not apage_bactive (str_name)    then            '如对象不存在则新建一对象
        apage_load str_name, str_table, str_id, str_sqlend
    end if
        a1=application (str_name)
        a1(2)=now()
        application.lock
            application (str_name