绕过 jQuery.autocomplete(1.02) 上的所有缓存

发布于 2024-07-16 19:15:46 字数 940 浏览 5 评论 0原文

我在搜索框中使用jQuery.autocomplete(1.02),并且我想要精确字符串和子字符串匹配。 我不关心(还!)数据库负载,我很高兴它每次击键都会触发查询并完全绕过缓存 - 我只是不想错过任何东西。

为此,我尝试设置 cacheLength=1(允许的最小值),但自动完成功能拒绝为每个按键触发 GET 请求。

searchbox          GET_request

   'a'       ->    http://localhost/service_search_request?q=a
   'ar'      ->    http://localhost/service_search_request?q=ar
   'ars'     ->    http://localhost/service_search_request?q=ars

相反,它发送了第一个和第三个,但错过了第二个,给了我“ar”的错误结果:-/我已经清除了缓存和会话,但看起来某种缓存仍在进行。 AFAIK 我没有进行代理,每次我都会进行轮班刷新。 看起来这种行为很可能来自 jQuery.autocomplete 本身。

所以我的问题是...

A) 这看起来有可能吗? 即它是一个功能,还是一个错误?

B) 如果是这样,有没有一种干净的方法可以解决它?...

C) 如果没有,您会使用什么自动完成功能?

当然D)不,你只是错误地使用了它,你这个混蛋!总是有可能的,而且实际上我更愿意花时间沿着这条路走下去 - 假设它带有指向我找不到/阅读的文档!

干杯,

罗杰:)

I am using jQuery.autocomplete(1.02) on my search box and I want exact string and substring matching. I don't care (yet!) about the database load, I'm happy for it to fire off a query every keystroke and bypass the caching entirely - I just don't want anything missed.

To this end I have tried setting cacheLength=1, the minimum permitted, but the autocomplete function refuses to fire off a GET request for each key up.

searchbox          GET_request

   'a'       ->    http://localhost/service_search_request?q=a
   'ar'      ->    http://localhost/service_search_request?q=ar
   'ars'     ->    http://localhost/service_search_request?q=ars

Instead, it sends the first and the third and misses the second, giving me the wrong results for 'ar' :-/ I've cleared my cache and sessions but it looks like some sort of caching is still going on. AFAIK I have no proxying going on and I'm shift-refreshing each time. It looks likely then that this behavior is from jQuery.autocomplete itself.

So my questions are...

A) Does this seem likely? i.e. is it a feature, or maybe a bug?

B) If so is there a clean way around it?...

C) If not, what autocomplete would you use instead?

Naturally D) No you're just using it incorrectly you douche! is always a possibility, and indeed the one I'd prefer having spent time going down this road - assuming it comes with a link to the docs I've failed to find / read!

Cheers,

Roger :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

海夕 2024-07-23 19:15:46

我想知道为什么 cacheLength 不起作用,但自动完成也遇到问题。 恕我直言,其中有错误。 但是,在选项列表中,有一个ma​​tchSubset< /strong> 你可以设置为 false。

编辑:
第 335 行附近有一个名为“request”的函数。 您可以向其中添加一些调试消息,看看会发生什么:(注意:您需要安装 firebug 或“控制台”未知)

function request(term, success, failure) {

    console.debug("ac request...");

    if (!options.matchCase)
        term = term.toLowerCase();

    var data = cache.load(term);

    console.debug("ac request 1, loaded data from cache: " + data + " term: " + term);

    // recieve the cached data
    if (data && data.length) {
        success(term, data);
    // if an AJAX url has been supplied, try loading the data now
    } else if( (typeof options.url == "string") && (options.url.length > 0) ){

        console.debug("ac request 2, data is not in the cache, request it");

“flushCache”可以轻松地在您可以附加/设置为选项的功能中使用。 如果后端有更多数据,我用它来清除缓存:

formatItem: function (data,i,n,value){
    if(i === (this.max -1)){
        console.debug("flushCache");
        jQuery(this).flushCache();
    }

    return data[1] + " (" + data[0] + ")";
}

I wonder why cacheLength doesn't work, but had trouble with autocomplete too. IMHO, there are errors in it. However, in the list of options, there is a matchSubset you could set to false.

EDIT:
somewhere around line 335 is a function called "request". You could add some debug messages to it, to see what happens: (note: you need firebug installed or "console" will be unknown)

function request(term, success, failure) {

    console.debug("ac request...");

    if (!options.matchCase)
        term = term.toLowerCase();

    var data = cache.load(term);

    console.debug("ac request 1, loaded data from cache: " + data + " term: " + term);

    // recieve the cached data
    if (data && data.length) {
        success(term, data);
    // if an AJAX url has been supplied, try loading the data now
    } else if( (typeof options.url == "string") && (options.url.length > 0) ){

        console.debug("ac request 2, data is not in the cache, request it");

"flushCache" can easily be used in the function you can attach / set as options. I used this, to clear the Cache, if there could be more data in the backend:

formatItem: function (data,i,n,value){
    if(i === (this.max -1)){
        console.debug("flushCache");
        jQuery(this).flushCache();
    }

    return data[1] + " (" + data[0] + ")";
}
極樂鬼 2024-07-23 19:15:46

我有同样的问题。 尽管我已将选项cacheLength 设置为1,但缓存不起作用。

使用您的解决方案在每个打印术语后调用flushCache 函数,它可以工作。 我无法使用:

if(i === (this.max -1)){

因为过滤后“i”为 1,但“this.max”仍然为 25,因为原始后端查询导致返回 25 行。

但是,此错误在输入包含瑞典语字符“å”、“ä”或“ö”的单词时出现。 因此,兑现可能会按预期进行,但不适用于这些特殊字符。

反正。 对我来说,解决方案是始终在 formatItem() 函数中调用 flashCache 控件:

function formatItem(row, position, n, term) {

    if($("#keywords-h").length > 0){
        $("#keywords-h").flushCache();
        }

        // format Item
        return "<span>" + row[0] + "</span>";
}

希望这对某人有帮助,如果有人对特殊字符遇到相同的问题,请发表回复。

I am having the same problem. Caching doesn't work although I have set the option cacheLength to 1.

With your solution to call the flushCache function after each printed term it works. I couldn't use the:

if(i === (this.max -1)){

since 'i' was e.g 1 after filtering but 'this.max' still 25 as the original backend query resulted in 25 returned rows.

However, this bug ONLY appears when typing words that contain the swedish characters 'å', 'ä' or 'ö'. So maybe the cashing works as expected but not with these special characters.

Anyway. the solution for me was to always call the flushCache control in the formatItem() function:

function formatItem(row, position, n, term) {

    if($("#keywords-h").length > 0){
        $("#keywords-h").flushCache();
        }

        // format Item
        return "<span>" + row[0] + "</span>";
}

Hope this helps someone and if someone is having the same problems with special characters please post a reply.

千と千尋 2024-07-23 19:15:46

显然已经过了 18 个月了,但是

缓存长度:0

选项中的 对我有用。 那么也许最新版本已经修复了该错误?

Have obviously come to this 18 months on, but

cacheLength: 0

in the options worked for me. So maybe latest release has fixed the bug?

我们的影子 2024-07-23 19:15:46

这对我有用。

function requestData(q) {
   if (!options.matchCase) q = q.toLowerCase();

   //-- I turned off this line
   // var data = options.cacheLength ? loadFromCache(q) : null;

   //-- And added this line of code
   var data = null;

This worked for me.

function requestData(q) {
   if (!options.matchCase) q = q.toLowerCase();

   //-- I turned off this line
   // var data = options.cacheLength ? loadFromCache(q) : null;

   //-- And added this line of code
   var data = null;
自演自醉 2024-07-23 19:15:46

有一个选项可以禁用子集匹配,例如

$("#query").autocomplete(
    url,
    {
        matchSubset: false
    }
)

There is an option to disable subset matching e.g.

$("#query").autocomplete(
    url,
    {
        matchSubset: false
    }
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文