最近写的一个asp缓存函数
作者:hayden 来源:烦恼's BLOG 发布时间:2008-11-25 14:07:00
标签:缓存,函数,asp
关于asp缓存函数,类什么的,在网上可以说笔笔皆是,为啥我要不辞辛苦去写一个呢?
大概看了下,各有各的优点吧,可是大部分好像不可以缓存数据额,还得把数据用一定的符号相隔转成一个变量去缓存,取出来用的时候还要split转成数组,有些麻烦了,所以这就重写了一个,也给大家分享分享,有什么更好的想法,欢迎来“稿”!谢谢~
程序代码
<%
'***********************************************
'函数名:getcache
'作 用:将需要缓存的内容,置入缓存中,并读取出来,如果缓存中存在该内容,则直接从缓存读取!
'作 者: 静¢脉(hayden)
'时 间: 2007-12-21
'参 数:funsname ---- 需要缓存的内容
' isreset ---- 是否更新[值:0(根据时间或判断缓存为空时自动更新)、1(主动更新)]
' isarr ---- 所缓存的内容是否为一个数据[0为字符串,1为数组]
' timeinfo ---- 缓存更新时间,单位为秒,当值为0时,则只在缓存为空时,才更新
'返回值:缓存名为"funsname”的内容
'***********************************************
Function getcache(funsname,isreset,isarr,timeinfo)
dim domain : domain = "www.mysuc.com" '缓存域
Dim temp_getconfig
Dim re_getcache : re_getcache = False
Dim temp_isarray_type : temp_isarray_type = False
Dim Appfunsname : Appfunsname = Replace(Replace(Replace(funsname,"(",""),")",""),",",".")
If isarr = 1 Then temp_isarray_type = True
If isreset = 1 Then re_getcache = True
If isreset = 2 Then
execute("temp_getconfig="&funsname)
getcache = temp_getconfig
Exit Function
End If
If Application(domain&"_"&Appfunsname&"_time") = "" And timeinfo<>0 Then re_getcache = True
If Not re_getcache Then
If temp_isarray_type Then
If Not IsArray(Application(domain&"_"&Appfunsname)) Then re_getcache = True
Else
If Application(domain&"_"&Appfunsname) = "" Then re_getcache = True
End If
End If
If Not re_getcache And timeinfo<>0 Then
If Int(DateDiff("s",Application(domain&"_"&Appfunsname&"_time"),now()))>timeinfo Then re_getcache = True
End If
If re_getcache Then
execute("temp_getconfig="&funsname)
Application.Lock
Application(domain&"_"&Appfunsname) = temp_getconfig
Application(domain&"_"&Appfunsname&"_time") = Now()
Application.UnLock
Else
temp_getconfig=Application(domain&"_"&Appfunsname)
End If
getcache = temp_getconfig
End Function
%>
调用示例:
程序代码
<%
Function out_test1 '返回一个字符串的示例函数
out_test1="这里是一个字符串"
End Function
Function out_test2 '返回一个数组的示例函数
Dim temp_out_test2
temp_out_test2="这里.是.一个.数组"
out_test2=Split(temp_out_test2,".")
End Function
Dim i
'字符串缓存(将函数out_test1从缓存读取并输出)
Dim str2 : str2 = getcache("out_test1",0,0,180) '通过getcache函数读取缓存.刷新时间为180秒,(当out_test1缓存为空,会自动访问函数out_test1输出,并同时置入缓存~)
response.write str2
response.write "<BR><BR><BR>"
'数组缓存(将函数out_test2从缓存读取并输出)
Dim str1 : str1 = getcache("out_test2",0,1,180) '同上(字符串缓存说明)
For i = 0 To UBound(str1)
response.write str1(i) & "<BR>"
Next
%>


猜你喜欢
- 描述在linux中获取进程cmdline时遇到隐藏符号问题,如下:[root@vm010066016161 /root]#cat /proc
- 问题描述像这样的图,我想把右边的colorbar设置成和主图一样高度方法0. plt.colorbar参数介绍https://matplot
- 本文详细分析了Yii框架的登录流程。分享给大家供大家参考。具体分析如下:Yii对于新手来说上手有点难度,特别是关于session,cooki
- 当models中使用ManyToManyField进行多表关联的时候,需要使用字段的add()方法来增加关联关系的一条记录,让两个实例关联起
- 一、算法 1、算法的主要思想就是将一个中缀表达式(Infix expression)转换成便
- python中在实现一元线性回归时会使用最小二乘法,那你知道最小二乘法是什么吗。其实最小二乘法为分类回归算法的基础,从求解线性透视图中的消失
- 一.概述IO 内存是sql server最重要的资源,数据从磁盘加载到内存,再从内存中缓存,输出到应用端,在sql server 内存初探中
- 本文介绍了Python日期的加减等操作的示例,分享给大家,也给自己留个笔记1. 日期输出格式化所有日期、时间的api都在datetime模块
- 快速掌握 Mysql数据库对文件操作的封装在查看Mysql对文件的操作中,它在不同的操作系统上对文件的操作,除了使用标准C运行库函数,包括o
- 一般情况下,tensorflow里面变量初始化过程为: #variables ........... #......
- * 对子查询和Join进行了优化,包括对MyISAD和InnoB存储引擎分散范围内的批量索引访问。* 增加了 BACKUP DATABASE
- 注意:这种方法十分受光线变化影响自己在家拿着手机瞎晃的成果图:源代码:# -*- coding: utf-8 -*- ""
- 1. 取键:keys()方法#spyderbb={'人才/可怕':23,'伏地魔&波特':'
- centos6.x默认安装的python为2.6版本,今天换成了3.5版本这里不再讲如何升级python版本在安装完新的版本后,之前安装的插
- "神经衰弱"翻牌游戏考察玩家的记忆力,游戏的开头会短时间给你看一小部分牌的图案,当玩家翻开两张相同图案牌的时候,会消除,
- 今天要实现的功能就是以下这个功能:vue.js模拟日历插件好了废话不多说了 直接上代码了css:*{ margi
- 本文实例为大家分享了js贪吃蛇游戏的相关代码,供大家参考,具体内容如下<!DOCTYPE html><html lang=
- 分布式锁一般有三种实现方式:1. 数据库乐观锁;2. 基于Redis的分布式锁;3. 基于ZooKeeper的分布式锁。本篇博客将介绍第二种
- python数组添加整行或整列代码如下,见注释:import numpy as npm_list=[[1,2,3],[3,4,5]]m_ar
- 以country.xml为例,内容如下:<?xml version="1.0"?><data>