1
0
forked from GitHub/gf-core

PGF web service: add unlexers and enable client side caching

Most PGF web API commands that produce linearizations now accept an
unlexer parameter. Possible values are "text", "code" and "mixed".

The web service now include Date and Last-Modified headers in the HTTP,
responses. This means that browsers can treat responses as static content and
cache them, so it becomes less critical to cache parse results in the server.

Also did some cleanup in PGFService.hs, e.g. removed a couple of functions
that can now be imported from PGF.Lexing instead.
This commit is contained in:
hallgren
2014-04-09 17:51:25 +00:00
parent f2cc1d2c68
commit 43e61a1e3b
3 changed files with 123 additions and 93 deletions

View File

@@ -1,4 +1,4 @@
module Cache (Cache,newCache,flushCache,readCache) where
module Cache (Cache,newCache,flushCache,readCache,readCache') where
import Control.Concurrent.MVar
import Data.Map (Map)
@@ -21,7 +21,10 @@ flushCache :: Cache a -> IO ()
flushCache c = modifyMVar_ (cacheObjects c) (const (return Map.empty))
readCache :: Cache a -> FilePath -> IO a
readCache c file =
readCache c file = snd `fmap` readCache' c file
readCache' :: Cache a -> FilePath -> IO (UTCTime,a)
readCache' c file =
do v <- modifyMVar (cacheObjects c) findEntry
modifyMVar v readObject
where
@@ -35,4 +38,4 @@ readCache c file =
x' <- case m of
Just (t,x) | t' == t -> return x
_ -> cacheLoad c file
return (Just (t',x'), x')
return (Just (t',x'), (t',x'))