java - Autocomplete with Ehcache -
i have several autocomplete fields within form i'm developing. largest containing 20k records , smallest containing around 1k. until i've used treemap handle task, i'm finding in efficient. current structure looked this.
private sortedmap<string, set<string>> cache; public autocompletecacheserviceimpl() { cache = collections.synchronizedsortedmap(new treemap<string, set<string>>()); }
while being populated so,
private void populatecache(string id, string name) { int len = name.length(); (int = 1; <= len; i++) { string key = name.substring(0, i).tolowercase(); if(this.cache.containskey(key)) { set<string> exist = cache.get(key); if(!exist.contains(id)) { exist.add(id); } } else { set<string> _e = new hashset<string>(); _e.add(id); this.cache.put(key, _e); } } }
output 1 h 1 ho 1 hou 1 hous 1 house
i hoping replace cache implementation ehcache, i'm not familiar it. i'm wondering if has recommendations on setting response times on keystrokes remain 500ms or less.
i seen page http://ehcache.org/documentation/get-started/getting-started
but perhaps current populating method causing me on better approach.
does have thoughts?
if optimize performance, have @ patricia tries, there implementation here implements sortedmap.
Comments
Post a Comment