DIRECTORY
Basics USING [charsPerWord, UnsafeBlock],
IO USING [EndOfStream, GetChar, GetLength, STREAM, UnsafeGetBlock],
RefText USING [ObtainScratch, ReleaseScratch],
Rope USING [Concat, Compare, FromRefText, ROPE],
SymTab USING [Create, Delete, EachPairAction, Fetch, GetSize, Insert, Pairs, Ref],
YggDID USING [DID, StreamsForDID],
YggDummyProcess USING [Detach, MsecToTicks, Pause, SetTimeout, Ticks],
YggEnvironment USING [AccessRights, LockMode, LockOption, TransID],
YggInternal USING [OpenDoc],
YggLock USING [Failed, MakeLockID, Set],
YggMonitoringLog USING [LockConflictInfo, notice],
YggOpenDoc USING [Register],
YggRep USING [AccurateGMT, AccurateGMTRep, AccurateGMTRepByteSize, AttributePreambleByte, AttributeValue, Bits, BitsRep, date, float, int, rope, shortRope, TypedPrimitiveElement, unknown, uninterpretedBytes, VDoc, VDocRep],
YggTransContext USING [EstablishTransactionContext, TransactionWork],
YggVolatileObjectCache;
Cache management utilities
LookupDIDInCache:
PUBLIC
ENTRY
PROC [did:
DID]
RETURNS [document: YggRep.VDoc ←
NIL] ~ {
Given a DID, return the volatile form of the document if it is cached. Block until object is cached, if it is reserved.
found: BOOL;
val: REF;
DO
[found, val] ← SymTab.Fetch[x: didCache, key: did^];
IF found
THEN {
entry: cacheEntry;
entry ← NARROW[val];
IF entry.users # 0 THEN {WAIT myCondition; LOOP;};
RETURN[entry.document];
};
ENDLOOP;
};
ReserveDIDInCache:
PUBLIC
ENTRY PROC [did:
DID] ~ {
Given a DID, reserve this DID as being volatized. Calling this procedure obligates the caller to call CacheDID to clear the reservation.
found: BOOL;
val: REF;
[found, val] ← SymTab.Fetch[x: didCache, key: did^];
IF found
THEN {
entry: cacheEntry;
entry ← NARROW[val];
WHILE entry.users # 0 DO WAIT myCondition; ENDLOOP;
entry.users ← 1;
}
ELSE ERROR;
};
UnreserveDIDInCache:
PUBLIC
ENTRY PROC [did:
DID] ~ {
Undo a reservation.
found: BOOL;
val: REF;
[found, val] ← SymTab.Fetch[x: didCache, key: did^];
IF found
THEN {
entry: cacheEntry;
entry ← NARROW[val];
entry.users ← entry.users - 1;
BROADCAST myCondition;
}
ELSE ERROR;
};
CacheDID:
PUBLIC
ENTRY PROC [did:
DID, document: YggRep.VDoc] ~ {
Add this document to the cache for the did.
found: BOOL;
val: REF;
[found, val] ← SymTab.Fetch[x: didCache, key: did^];
IF found
THEN {
entry: cacheEntry;
entry ← NARROW[val];
entry.document ← document;
}
ELSE {
IF ~SymTab.Insert[x: didCache, key: did^, val: NEW[cacheEntryRep ← [0, document]]] THEN ERROR;
BROADCAST myCondition;
};
};
InvalidateDID:
PUBLIC
ENTRY PROC [did:
DID] ~ {
Remove this did from the cache.
found: BOOL;
val: REF;
[found, val] ← SymTab.Fetch[x: didCache, key: did^];
IF found
THEN {
entry: cacheEntry;
entry ← NARROW[val];
WHILE entry.users # 0 DO WAIT myCondition; ENDLOOP;
[] ← SymTab.Delete[x: didCache, key: did^];
};
};
SetSizeOfDIDCache:
PUBLIC ENTRY PROC [size:
INT] = {
Remove this did from the cache.
desiredSizeOfDIDCache ← size;
};