一个openlaszlo使用flash的共享对象实现保存客户端信息的例子

本文介绍了一个使用LocalCache进行数据缓存的应用实例,通过在浏览器中保存和读取选择状态来展示其基本用法。LocalCache允许应用程序维护状态或提供用户界面创建键值对存储,实现简单的本地文件存储功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文在这里:
http://forum.openlaszlo.org/showthread.php?p=25458#post25458

部分摘录如下:

-----------------------------------------------
localcache.lzx
-----------------------------------------------

< library >

<!---
*  LocalCache
*
*  A dictionary  for  localy cached data.
*  It allows an application to maintain state or to enable the app
*  to provide a user  with  an interface to create a list of keys
*  and save and load data  for  each key,
*  essentially creating a temporary local file store
*  of xml documents or datasets
*
*  We have APP_NAME and CACHE_VER constants
*  that we use to version the keysets locally
*  so that anytime that an app needs to make a change
*  to the local datastructure it can bump up the version
*  to avoid datastructure version problems between instances  in  the wild
*  the appname is so that different apps from the same domain
*  and which use the same code, don ' t step on each other ' s data
*
*  expected use  for  maintaining application state
*   //  oninit
*   if  (gLocalCache.testWriteable())
*   if (gLocalCache.checkLocalKey( " mysavedstate " )) {
* mydata=gLocalCache.getLocalData("mydataname");
* // create LzDataElement with mydata
* }
  else   {
* // create key and initialize with data
* gLocalCache.saveLocalKey("mydataname");
* gLocalCache.saveLocalData("mydataname", ds_state.serialize());
* }

*  }  else   {
* // deal with the case where local data has been disabled
* }

*
-->

<!--  CONSTANTS  -->
< script >
var  APP_NAME  = " app " ;
var  CACHE_VER  =   " 1 " ;
</ script >

<!--  CLASSES  -->
< script >
<! [CDATA[

// --------------------------------------------------------------------------------
//
 LocalCache Constructor
//
--------------------------------------------------------------------------------
function  LocalCache()  {
// Debug.write("created");
}

LocalCache.prototype 
=   new  Object();
LocalCache.prototype.constructor 
=  LocalCache;
Object.registerClass(
" LocalCache " , LocalCache);

// --------------------------------------------------------------------------------
//
 testWriteable
//
--------------------------------------------------------------------------------
LocalCache.prototype.testWriteable  =   function () {
var retval = true;
var tstWriteObj = SharedObject.getLocal("tst");
if(!tstWriteObj.flush(10000)) {
// local cache is disabled
retval = false;
}

delete tstWriteObj;
return retval;
}


// --------------------------------------------------------------------------------
//
 saveLocalKeyDataPair
//
--------------------------------------------------------------------------------
LocalCache.prototype.saveLocalKeyDataPair  =   function (key, data) {
if (this.testWriteable()){
if (this.checkLocalKey(key)){
this.saveLocalData(key,data);
return "Saved the data, overwriting anything that was there";
}
 else {
this.saveLocalKey(key);
this.saveLocalData(key,data);
return "Created the key and saved the data.";
}

}
 else {
return "The user has disabled the local shared object";
}

}


// --------------------------------------------------------------------------------
//
 getLocalData
//
--------------------------------------------------------------------------------
LocalCache.prototype.getLocalData  =   function (key) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
return localObj.data[key];
}


// --------------------------------------------------------------------------------
//
 getLocalKeys
//
--------------------------------------------------------------------------------
LocalCache.prototype.getLocalKeys  =   function () {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
return localObj.data.keys;
}


// --------------------------------------------------------------------------------
//
 saveLocalKey
//
--------------------------------------------------------------------------------
LocalCache.prototype.saveLocalKey  =   function (key) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);

if(localObj.data.keys == null{
localObj.data.keys 
= new Array(key);
}
 else {
ifthis.checkLocalKey(key)){
// then it already exists
}
 else {
localObj.data.keys.push(key);
localObj.data[key] 
= "";
}

}

localObj.flush();
delete localObj;
}


// --------------------------------------------------------------------------------
//
 checkLocalKey
//
--------------------------------------------------------------------------------
LocalCache.prototype.checkLocalKey  =   function (key) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
var len = localObj.data.keys.length;
var retval = false;
for(i=0; i<len; i++){
if(localObj.data.keys[i] == key){
// it exists
retval = true;
}

}

return retval;
}


// --------------------------------------------------------------------------------
//
 deleteLocalKey
//
--------------------------------------------------------------------------------
LocalCache.prototype.deleteLocalKey  =   function (key) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
var len = localObj.data.keys.length;

// delete the data if it exists first
this.deleteLocalData(key);

// then find and remove the key from the list
for(i=0; i<len; i++){
if(localObj.data.keys[i] == key){
localObj.data.keys.splice(i,
1);
}

}

localObj.flush();
delete localObj;
}


// --------------------------------------------------------------------------------
//
 saveLocalData
//
--------------------------------------------------------------------------------
LocalCache.prototype.saveLocalData  =   function (key, data) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
localObj.data[key] 
= data;
localObj.flush();
delete localObj;
}


// --------------------------------------------------------------------------------
//
 deleteLocalData
//
--------------------------------------------------------------------------------
LocalCache.prototype.deleteLocalData  =   function (key) {
var localObj = SharedObject.getLocal( APP_NAME+CACHE_VER);
delete localObj.data[key];
localObj.flush();
delete localObj;
}

]]
>
</ script >

<!--  INITIALIZATION  -->
< script >
var  gLocalCache  =   new  LocalCache();
</ script >
</ library >

---------------------------------------------------------------
saveselectionsample.lzx
--------------------------------------------------------------

 

< canvas >
< debug y = " 700 "  width = " 750 "  height = " 175 " />
< include href = " localcache.lzx " />

< dataset name = " dsselection1 " >
< items >
< item value = " item1 " > item one </ item >
< item value = " item2 " > item two </ item >
< item value = " item3 " > item three </ item >
< item value = " item4 " > item four </ item >
</ items >
</ dataset >

< dataset name = " dsselection2 " >
< items >
< item value = " item1 " > item one </ item >
</ items >
</ dataset >

< view name = " interface " >
< simplelayout axis = " y " />
< view name = " buttons "   >
< wrappinglayout axis = " y " />

< button text = " saveSelections "   >
< method event = " onclick " >
<! [CDATA[
var  dp  =  dsselection1.getPointer();
//  we should maintain a variable for the first check that fails and use that
//
 instead of calling checkLocalKey each time or the user will get the dialog box
//
 each time if they've disabled it and want to keep it disabled.
if (gLocalCache.checkLocalKey( " dsselections " )) {
gLocalCache.saveLocalKeyDataPair(
"dsselections", dp.serialize());
}
  else   {
// at this point local shared objects must be disabled or the key would exist
//
 from the initial call of loadSelections
//
 nevertheless we might want to reinitialize it here
//
 in case the user has changed their settings
//
 durring the session from disabled to enabled
//
 gLocalCache.saveLocalKeyDataPair("dsselections", dp.serialize());
}

]]
>
</ method >
</ button >

< button text = " loadSelections "   >
< method event = " onclick " >
<! [CDATA[
var  dp  =  dsselection2.getPointer();
if (gLocalCache.checkLocalKey( " dsselections " )) {
// Debug.write("localdata exits");
var selCacheNode = LzDataNode.stringToLzData(gLocalCache.getLocalData ("dsselections" ))
dsselection2.setChildNodes([selCacheNode.getFirstChild()]);
// Debug.write("loaded and serialized:"+ dp.serialize());
}
  else   {
// Debug.write("--in-else-lso-needs-initializing--" );
gLocalCache.saveLocalKeyDataPair("dsselections", dp.serialize());
}

]]
>
</ method >
</ button >
</ view >

< combobox id = " gogocombo1 "  editable = " false " >
< textlistitem name = " textguy1 "
datapath
= " dsselection1:/items/item "
text
= " gogo "   />
</ combobox >

< combobox id = " gogocombo2 "  editable = " false " >
< textlistitem name = " textguy2 "
datapath
= " dsselection2:/items/item "
text
= " gogo gadget "   />
</ combobox >
</ view >
</ canvas >

 

该例子后面有评价认为,如果有多个用户同时使用一个browser,那么他们有可能共享相同的shareobject,除非在shareobject中区分用户,而且这个临时数据在某一个用户清空缓存的时候清掉所有的临时数据,所以还是局限性。

资源下载链接为: https://pan.quark.cn/s/1bfadf00ae14 在 Linux 系统中,查找域名或主机名对应的 IP 地址是网络管理中的一项基础且关键任务,对于排查网络故障、调试网络问题以及监控网络服务是否正常运行等场景都非常重要。本文将介绍五种在 Linux 终端查询域名 IP 地址的方法。 首先,dig 命令(全称 Domain Information Groper)是一个功能强大的 DNS 查询工具,能够向 DNS 服务器发送查询请求并获取详细的响应信息。如果需要查询单个域名的 IP 地址,可以使用命令 dig 2daygeek.com +short 。此外,还可以通过编写 bash 脚本,将包含域名的文本文件中的域名逐个读取,然后利用 dig 命令进行查询,从而实现批量查询域名 IP 地址的功能。 其次,host 命令是一个简单易用的 DNS 查询工具,主要用于将域名解析为 IP 地址。要获取某个域名的 IP 地址,直接使用 host 2daygeek.com 即可。如果只想显示 IP 地址部分,可以通过管道结合 grep 和 sed 命令来实现,例如:host 2daygeek.com | grep "has address" | sed s/has address/-/g 。 再者,nslookup 命令也是一种常用的 DNS 查询工具,它支持交互式查询 DNS 信息。通过 nslookup 2daygeek.com 可以查询域名的 IP 地址。若要以非交互式的方式只显示 IP 地址,可以使用命令 nslookup 2daygeek.com | awk /^Address:/ {print $2} 。 另外,fping 命令与传统的 ping 命令不同,它不会直接进行 DNS 查询,而是通过发送 ICMP Echo Request(pi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值