All Downloads are FREE. Search and download functionalities are using the official Maven repository.

asset.pipeline.CachePersister.groovy Maven / Gradle / Ivy

Go to download

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