asset.pipeline.CachePersister.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of asset-pipeline-core Show documentation
Show all versions of asset-pipeline-core Show documentation
JVM Asset Pipeline library for serving static web assets, bundling, minifying, and extensibility for transpiling.
The newest version!
package asset.pipeline
import groovy.transform.CompileStatic
/**
* Receives asynchronous cache persistance requests and executes them.
* Also acts as a debouncer
*
* @author David Estes
*/
// @CompileStatic
public class CachePersister extends Thread {
public Integer delay = 0
public Boolean ran = true
public final Integer RUN_DELAY = 1000
public void run() {
while(true) {
sleep(RUN_DELAY)
if(ran == false) {
delay -= RUN_DELAY
if(delay <= 0) {
CacheManager.save()
ran = true
}
}
}
}
/**
* Asynchronously triggers a save with a debounce delay to reduce excessive persistence calls
* @param delay (milliseconds) between debounce save
*/
public void debounceSave(Integer delay) {
this.delay = delay
ran = false
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy