packages/@git/url_0eb7c89453c87681ed15/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/store.aug
OpenID Connect login application · Dependency source and specification
This is the exact dependency version used by this example.
Code
// Generated by aug spec. This is a copy of the installed dependency source.
/** The bounded store could not accept another live entry. */
StoreFull() implements Error:
pass
record _Entry<T implements Data>(T value, int expires)
/** A bounded, expiring capability for immutable values. Each generic DI binding has its own table. */
capability ExpiringStore<T implements Data>:
/** Remove expired entries, then store at most 512 live entries. Time is supplied by the caller. */
put(string key, T value, int expires, int now) uses ExpiringStore.put unless StoreFull
/** Atomically remove a value. Expired or absent entries return null. */
take(string key, int now) returns optional T uses ExpiringStore.take
/** Read a live value without consuming it. */
get(string key, int now) returns optional T uses ExpiringStore.get
/** A synchronized table with short critical sections and no I/O while locked. */
MemoryStore<T implements Data>() implements ExpiringStore<T>:
Shared<Map<string,_Entry<T>>> _entries = Shared(value=Map<string, _Entry<T>>())
put(string key, T value, int expires, int now) unless StoreFull:
entry = _Entry<T>(value=value, expires=expires)
lock _entries as entries:
for (name, saved) in entries:
if saved.expires <= now:
entries.take(key=name)
if entries.length() >= 512 and (not entries.contains(key=key)):
throw StoreFull()
entries.set(key=key, value=entry)
take(string key, int now) returns optional T:
lock _entries as entries:
match entries.take(key=key):
when null:
return null
when some saved:
if saved.expires <= now:
return null
return saved.value
get(string key, int now) returns optional T:
lock _entries as entries:
match entries.get(key=key):
when null:
return null
when some saved:
if saved.expires <= now:
return null
return saved.value// Generated by aug spec. This is a copy of the installed dependency source.
/** The bounded store could not accept another live entry. */
StoreFull() implements Error {
pass
}
record _Entry<T implements Data>(T value, int expires)
/** A bounded, expiring capability for immutable values. Each generic DI binding has its own table. */
capability ExpiringStore<T implements Data> {
/** Remove expired entries, then store at most 512 live entries. Time is supplied by the caller. */
put(string key, T value, int expires, int now) uses ExpiringStore.put unless StoreFull
/** Atomically remove a value. Expired or absent entries return null. */
take(string key, int now) returns optional T uses ExpiringStore.take
/** Read a live value without consuming it. */
get(string key, int now) returns optional T uses ExpiringStore.get
}
/** A synchronized table with short critical sections and no I/O while locked. */
MemoryStore<T implements Data>() implements ExpiringStore<T> {
Shared<Map<string,_Entry<T>>> _entries = Shared(value=Map<string, _Entry<T>>())
put(string key, T value, int expires, int now) unless StoreFull {
entry = _Entry<T>(value=value, expires=expires)
lock _entries as entries {
for (name, saved) in entries {
if saved.expires <= now {
entries.take(key=name)
}
}
if entries.length() >= 512 and (not entries.contains(key=key)) {
throw StoreFull()
}
entries.set(key=key, value=entry)
}
}
take(string key, int now) returns optional T {
lock _entries as entries {
match entries.take(key=key) {
when null {
return null
}
when some saved {
if saved.expires <= now {
return null
}
return saved.value
}
}
}
}
get(string key, int now) returns optional T {
lock _entries as entries {
match entries.get(key=key) {
when null {
return null
}
when some saved {
if saved.expires <= now {
return null
}
return saved.value
}
}
}
}
}Compiled specification
StoreFull · class · source
The bounded store could not accept another live entry. It implements Error.
ExpiringStore · capability interface · source
A bounded, expiring capability for immutable values. Each generic DI binding has its own table. The type parameters are T which must satisfy Data.
ExpiringStore.put · source
Remove expired entries, then store at most 512 live entries. Time is supplied by the caller. It takes key as a string, value as T, and expires and now as integers.
It can call ExpiringStore.put. Failures can raise StoreFull.
ExpiringStore.take · source
Atomically remove a value. Expired or absent entries return null. It takes key as a string and now as an integer.
It returns optional T. It can call ExpiringStore.take.
ExpiringStore.get · source
Read a live value without consuming it. It takes key as a string and now as an integer. It returns optional T. It can call ExpiringStore.get.
MemoryStore · class · source
A synchronized table with short critical sections and no I/O while locked. It implements ExpiringStore<T>. The type parameters are T which must satisfy Data. The read-only, private field _entries has type Shared<Map<string,_Entry<T>>> and starts as a Shared with value from an empty map from string to _Entry<T>.
MemoryStore.put · source
Remove expired entries, then store at most 512 live entries. Time is supplied by the caller. It takes key as a string, value as T, and expires and now as integers.
It can call ExpiringStore<T>.put. Failures can raise StoreFull.
It sets entry to a _Entry for T with value and expires. While holding the lock on _entries as mutable entries, for each name and saved in a snapshot of entries, if saved.expires is at most now, it removes the key name from entries. After the loop, it checks that the number of elements in entries is less than 512 or whether entries contains the key key returns true. It raises a StoreFull at the first failed check. source
It stores entry in entries under key. Release this lock when the block exits, including on return or failure. source
Checked interface
put(string key, T value, int expires, int now) returns void unless StoreFull uses ExpiringStore<T>.putIt takes key as a string, value as T, and expires and now as integers. It can call ExpiringStore<T>.put. Failures can raise StoreFull.
MemoryStore.take · source
Atomically remove a value. Expired or absent entries return null. It takes key as a string and now as an integer. It can call ExpiringStore<T>.take.
While holding the lock on _entries as mutable entries, it obtains entries.take with key. If no value is found, it returns null. The non-null result becomes saved. It returns null if saved.expires is at most now, or saved.value otherwise. source
Release this lock when the block exits, including on return or failure. source
Checked interface
take(string key, int now) returns optional T uses ExpiringStore<T>.takeIt takes key as a string and now as an integer. It can call ExpiringStore<T>.take.
MemoryStore.get · source
Read a live value without consuming it. It takes key as a string and now as an integer. It can call ExpiringStore<T>.get.
While holding the lock on _entries as mutable entries, it obtains the value under key in entries. If no value is found, it returns null. The non-null result becomes saved. It returns null if saved.expires is at most now, or saved.value otherwise. source
Release this lock when the block exits, including on return or failure. source
Checked interface
get(string key, int now) returns optional T uses ExpiringStore<T>.getIt takes key as a string and now as an integer. It can call ExpiringStore<T>.get.
_Entry · immutable record · source
It is private to this file. The type parameters are T which must satisfy Data. It takes value as T, kept read-only and expires as an integer, kept read-only.
Built-in operations follow the language reference.