Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Cloogle
cloogle.org
Commits
bdc85e72
Commit
bdc85e72
authored
Oct 19, 2016
by
Mart Lubbers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put cache in different submodule and generalize
parent
ed6a939e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
23 deletions
+36
-23
backend/Cache.dcl
backend/Cache.dcl
+8
-0
backend/Cache.icl
backend/Cache.icl
+23
-0
backend/CloogleServer.icl
backend/CloogleServer.icl
+5
-23
No files found.
backend/Cache.dcl
0 → 100644
View file @
bdc85e72
definition
module
Cache
from
StdOverloaded
import
class
toString
from
Data
.
Maybe
import
::
Maybe
from
Text
.
JSON
import
generic
JSONEncode
,
generic
JSONDecode
,
::
JSONNode
readCache
::
!
a
!*
World
->
(
Maybe
b
,
!*
World
)
|
toString
a
&
JSONDecode
{|*|}
b
writeCache
::
!
a
!
b
!*
World
->
(!
b
,
!*
World
)
|
toString
a
&
JSONEncode
{|*|}
b
backend/Cache.icl
0 → 100644
View file @
bdc85e72
implementation
module
Cache
import
StdFunc
from
Data
.
Func
import
$
import
Control
.
Monad
import
Control
.
Applicative
import
Data
.
Functor
import
Crypto
.
Hash
.
MD5
import
Text
.
JSON
import
Data
.
Error
import
StdFile
import
System
.
FilePath
import
System
.
File
import
Data
.
Tuple
toCacheFile
::
(
a
->
FilePath
)
|
toString
a
toCacheFile
=
((</>)
"./cache"
)
o
md5
o
toString
readCache
::
!
a
!*
World
->
(
Maybe
b
,
!*
World
)
|
toString
a
&
JSONDecode
{|*|}
b
readCache
k
w
=
appFst
(
join
o
fmap
(
fromJSON
o
fromString
)
o
error2mb
)
$
readFile
(
toCacheFile
k
)
w
writeCache
::
!
a
!
b
!*
World
->
(!
b
,
!*
World
)
|
toString
a
&
JSONEncode
{|*|}
b
writeCache
k
v
w
=
appFst
(
const
v
)
$
writeFile
(
toCacheFile
k
)
(
toString
$
toJSON
v
)
w
backend/CloogleServer.icl
View file @
bdc85e72
...
...
@@ -8,29 +8,22 @@ from TCPIP import :: IPAddress, :: Port, instance toString IPAddress
from
Data
.
Func
import
$
import
Data
.
List
import
Data
.
List
import
Data
.
Tuple
import
Data
.
Maybe
import
System
.
CommandLine
import
Text
.
JSON
import
Data
.
Functor
import
Control
.
Applicative
import
Control
.
Monad
import
Data
.
Error
from
Text
import
class
Text
(
concat
,
trim
,
indexOf
,
toLowerCase
),
instance
Text
String
,
instance
+
String
import
System
.
Time
import
System
.
FilePath
import
System
.
File
import
Crypto
.
Hash
.
MD5
from
SimpleTCPServer
import
::
LogMessage
{..},
serve
,
::
Logger
import
qualified
SimpleTCPServer
import
TypeDB
import
Type
CACHEPATH
:==
"./cache"
import
Cache
::
Request
=
{
unify
::
Maybe
String
,
name
::
Maybe
String
...
...
@@ -159,9 +152,9 @@ where
handle
::
!
TypeDB
!(
Maybe
Request
)
!*
World
->
*(!
Response
,
!*
World
)
handle
_
Nothing
w
=
(
err
E_INVALIDINPUT
"Couldn't parse input"
,
w
)
handle
db
(
Just
request
=:{
unify
,
name
,
page
})
w
#
cachefile
=
CACHEPATH
</>
(
md5
$
toString
request
)
#
(
mr
,
w
)
=
readCache
cachefile
w
|
isJust
mr
=
(
fromJust
mr
,
w
)
//Check cache
#
(
mr
,
w
)
=
readCache
request
w
|
isJust
mr
=
let
m
=
fromJust
mr
in
({
m
&
return
=
1
}
,
w
)
|
isJust
name
&&
size
(
fromJust
name
)
>
40
=
(
err
E_INVALIDNAME
"function name too long"
,
w
)
|
isJust
name
&&
any
isSpace
(
fromString
$
fromJust
name
)
...
...
@@ -182,24 +175,13 @@ where
// Response
|
isEmpty
results
=
(
err
E_NORESULTS
"No results"
,
w
)
// Save cache file
=
writeCache
cachefile
{
return
=
0
=
writeCache
request
{
return
=
0
,
msg
=
"Success"
,
data
=
results
,
more_available
=
Just
more
,
suggestions
=
suggestions
}
w
readCache
::
!
String
!*
World
->
(
Maybe
Response
,
!*
World
)
readCache
fp
w
=
case
readFile
fp
w
of
(
Error
_,
w
)
=
(
Nothing
,
w
)
(
Ok
s
,
w
)
=
case
fromJSON
$
fromString
s
of
Nothing
=
(
Nothing
,
w
)
(
Just
r
)
=
(
Just
{
r
&
return
=
1
,
msg
=
"Success, cache hit"
},
w
)
writeCache
::
!
String
!
Response
!*
World
->
(!
Response
,
!*
World
)
writeCache
fp
r
w
=
appFst
(
const
r
)
(
writeFile
fp
(
toString
$
toJSON
r
)
w
)
suggs
::
!(
Maybe
String
)
!
Type
!
TypeDB
->
Maybe
[(
Request
,
Int
)]
suggs
n
(
Func
is
r
cc
)
db
|
length
is
<
3
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment