查询缓存支持 jQuery 自动完成
我正在开发一个需要在搜索表单上自动完成字段的应用程序。该应用程序是 Railo 3.3 上的 CFML。我正在使用 jQuery UI 自动完成,并在服务器端实现了查找,如下所示:
private struct function getStationDetails(required numeric uic)
{
var qryCacheStations = new query();
var qryStations = new query();
var cacheData = "";
var resultData = "";
var stcResult = {};
qryCacheStations.setDatasource(variables.instance['dataSource']);
qryCacheStations.setSQL("select distinct uic, name, crs from stations order by name");
qryCacheStations.setCachedwithin(createTimeSpan(1,0,0,0));
cacheData = qryCacheStations.execute().getResult();
qryStations.setDBType("query");
qryStations.setAttributes(srcTbl = cacheData);
qryStations.setSQL("select name, crs from srcTbl where uic = :uic");
qryStations.addParam(name="uic",value=arguments.uic,CFSQLType="CF_SQL_INTEGER");
resultData = qryStations.execute().getResult();
stcResult = {
name = resultData['name'][1],
crs = resultData['crs'][1]
}
return stcResult;
}
基本上,我在第一次查找时将整个电台列表加载到缓存中,有效期为 1 天(数据很少更改),然后使用查询的查询将相关结果返回给客户端。
我的问题很简单;这种积极的缓存和 QoQs 技术是一个好的模式吗?性能似乎不错,内存占用也很合理(数据集很小),所以“感觉”还可以,但我正在向那些以前可能尝试过此操作并发现问题的人寻求任何建议?
任何想法将不胜感激。
I'm working on an application that requires an autocomplete field on a search form. The application is CFML on Railo 3.3. I'm using jQuery UI autocomplete and have implemented the lookup on the server-side like this:
private struct function getStationDetails(required numeric uic)
{
var qryCacheStations = new query();
var qryStations = new query();
var cacheData = "";
var resultData = "";
var stcResult = {};
qryCacheStations.setDatasource(variables.instance['dataSource']);
qryCacheStations.setSQL("select distinct uic, name, crs from stations order by name");
qryCacheStations.setCachedwithin(createTimeSpan(1,0,0,0));
cacheData = qryCacheStations.execute().getResult();
qryStations.setDBType("query");
qryStations.setAttributes(srcTbl = cacheData);
qryStations.setSQL("select name, crs from srcTbl where uic = :uic");
qryStations.addParam(name="uic",value=arguments.uic,CFSQLType="CF_SQL_INTEGER");
resultData = qryStations.execute().getResult();
stcResult = {
name = resultData['name'][1],
crs = resultData['crs'][1]
}
return stcResult;
}
Basically I'm loading the entire station list into the cache on the first lookup, with a 1 day expiry (the data rarely changes), then using a query of queries to return the relevant results back to the client.
My question is simply this; is this agressive caching and QoQs technique a good pattern? Performance seems good and the memory footprint is reasonable (the data set is quite small), so it 'feels' okay but I'm looking for any advice from those who have perhaps tried this before and discovered problems?
Any thoughts would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Jquery 自动完成
cacheLength: number
在客户端设置缓存启用,这样可以减少对服务器的调用次数并提高性能
you can use the Jquery auto complete
cacheLength: number
to set the caching enable at client side so number of calls to server can be reduced and performance can be improved
我使用了完全相同的技术并取得了巨大成功。
假设您的数据不会意外增长,您肯定在做正确的事情。
I used this exact same technique with great success.
You are definitely doing the right thing, assuming that your data doesn't grow unexpectedly.