Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the ClearExpiredCache() Function Dynamic? #20

Open
stravid87 opened this issue Mar 12, 2024 · 0 comments
Open

Make the ClearExpiredCache() Function Dynamic? #20

stravid87 opened this issue Mar 12, 2024 · 0 comments

Comments

@stravid87
Copy link
Contributor

Let's keep the call to ClearExpiredCache() in the initEncryptedTunnel() function if we can make it dynamic?

func ClearExpiredCache() { // should pass in a dynamic URL?
	// open the cache
	db := OpenDB(INDEXEDDB_CACHE, js.ValueOf(nil)) // Gets all layer8 caches for all URL
	db.Set("onsuccess", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		tx := args[0].Get("target").Get("result").Call("transaction", "static", "readwrite") // create a tx
		store := tx.Call("objectStore", "static") // get the object store called static
		index := store.Call("index", "_exp") // get the index "_exp"

		// get all the expired items
		bound := js.Global().Get("IDBKeyRange").Call("upperBound", js.ValueOf(time.Now().Unix())) // create an upper bound
		index.Call("openCursor", bound).Set("onsuccess", js.FuncOf(func(this js.Value, args []js.Value) interface{} { // user that upper bound to get the correct subset of data
			cursor := args[0].Get("target").Get("result")
			if cursor.IsUndefined() || cursor.IsNull() {
				return nil
			}
			store.Call("delete", cursor.Get("value").Get("url")) // get the value of whatever is store in the KEYPATH "url" and delete it
			cursor.Call("continue") // advance the cursor
			return nil
		}))
		return nil
	}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant