<* PRAGMA LL *>A cache of URL information.
MODULE; IMPORT HTML, TextRefTbl, Web; TYPE Info = REF RECORD header: Web.Header; contents: TEXT; END; VAR urlCacheMu := NEW(MUTEX); urlCacheEnabled := TRUE; urlCache := NEW(TextRefTbl.Default).init(); PROCEDURE URLCache Get (url: TEXT; VAR header: Web.Header; VAR contents: TEXT): BOOLEAN = VAR ref : REFANY; found := FALSE; BEGIN LOCK urlCacheMu DO IF urlCacheEnabled THEN found := urlCache.get(url, ref); IF found THEN header := NARROW(ref, Info).header; contents := NARROW(ref, Info).contents END END END; RETURN found END Get; PROCEDUREPut (url: TEXT; READONLY header: Web.Header; contents: TEXT) = BEGIN LOCK urlCacheMu DO IF urlCacheEnabled THEN VAR info := NEW(Info, header := header, contents := contents); BEGIN EVAL urlCache.put(url, info) END END END END Put; PROCEDUREEnable () = BEGIN LOCK urlCacheMu DO urlCacheEnabled := TRUE END END Enable; PROCEDUREDisable () = BEGIN LOCK urlCacheMu DO urlCacheEnabled := FALSE END END Disable; PROCEDUREFlush () = BEGIN LOCK urlCacheMu DO urlCache := NEW(TextRefTbl.Default).init() END END Flush; VAR htmlCacheMu := NEW(MUTEX); htmlCacheEnabled := TRUE; htmlCache := NEW(TextRefTbl.Default).init(); PROCEDUREGetHTML (url: TEXT; VAR html: HTML.T): BOOLEAN = VAR ref : REFANY; found: BOOLEAN := FALSE; BEGIN LOCK htmlCacheMu DO IF htmlCacheEnabled THEN found := htmlCache.get(url, ref); IF found THEN html := NARROW(ref, HTML.T) END END END; RETURN found END GetHTML; PROCEDUREPutHTML (url: TEXT; html: HTML.T) = BEGIN LOCK htmlCacheMu DO IF htmlCacheEnabled THEN EVAL htmlCache.put(url, html) END END END PutHTML; PROCEDUREEnableHTML () = BEGIN LOCK htmlCacheMu DO htmlCacheEnabled := TRUE END END EnableHTML; PROCEDUREDisableHTML () = BEGIN LOCK htmlCacheMu DO htmlCacheEnabled := FALSE END END DisableHTML; PROCEDUREFlushHTML () = BEGIN LOCK htmlCacheMu DO htmlCache := NEW(TextRefTbl.Default).init() END END FlushHTML; BEGIN END URLCache.