java - Grails - Implement Debounce Algorithm for AutoComplete Request in Controller -


in grails, have following code snippet.

class autocompletecontroller {    def getautocompletedata() {        // open db connection , data        // , other long , heavy computation        jsonstring(data: result)    } } 

i want implement debounce algorithm incoming request if comes the same user, same request data, , same user's ip address.

i have been looking @ implementing debounce in java however, don't have idea how integrating grails controller.

please me how implement in grails? looking implementation java annotation this:

class autocompletecontroller {    @debounce(delay = 1000) // ------------>>>>>> how implement annotation?    def getautocompletedata() {        // heavy logic        jsonstring(data: result)    } } 

put last request data hash session , compare actual data. simplest approach be:

def getautocompletedata() {    int hash = hashtherelevantparams()    if( null == session.cache ) session.cache = [:]    def result = session.cache[ hash ] ?: getresultthehardway()     session.cache.clear()    session.cache[ hash ] = result    jsonstring(data: result) } 

if thing should used in many locations, pack controller interceptor or filter. if need timeout-driven cache, add timestampt data, stored in session or use smart caching solution, google's guava


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -