Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
cloogle.org
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cloogle
cloogle.org
Commits
2ae3bdee
Verified
Commit
2ae3bdee
authored
Oct 19, 2016
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move pruning cache to separate container
parent
e5467e20
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
27 deletions
+28
-27
backend/Cache.icl
backend/Cache.icl
+1
-27
docker-compose.yml
docker-compose.yml
+6
-0
gc/Dockerfile
gc/Dockerfile
+5
-0
gc/gc.sh
gc/gc.sh
+16
-0
No files found.
backend/Cache.icl
View file @
2ae3bdee
...
...
@@ -2,7 +2,6 @@ implementation module Cache
import
StdFunc
import
StdTuple
import
StdOrdList
from
Data
.
Func
import
$
import
Control
.
Monad
import
Control
.
Applicative
...
...
@@ -11,14 +10,11 @@ import Crypto.Hash.MD5
import
Text
.
JSON
import
Data
.
Error
import
StdFile
import
System
.
Directory
import
System
.
FilePath
import
System
.
File
import
System
.
Time
import
Data
.
Tuple
CACHE_DIR
:==
"./cache"
CACHE_SIZE
:==
100
toCacheFile
::
(
a
->
FilePath
)
|
toString
a
toCacheFile
=
((</>)
CACHE_DIR
)
o
md5
o
toString
...
...
@@ -27,26 +23,4 @@ readCache :: !a -> *World -> (Maybe b, !*World) | toString a & JSONDecode{|*|} b
readCache
k
=
appFst
(
join
o
fmap
(
fromJSON
o
fromString
)
o
error2mb
)
o
readFile
(
toCacheFile
k
)
writeCache
::
!
a
!
b
->
*
World
->
*
World
|
toString
a
&
JSONEncode
{|*|}
b
writeCache
k
v
=
purgeCache
o
snd
o
writeFile
(
toCacheFile
k
)
(
toString
$
toJSON
v
)
purgeCache
::
*
World
->
*
World
purgeCache
w
#
(
fs
,
w
)
=
readDirectory
CACHE_DIR
w
|
isError
fs
=
w
#
fs
=
map
((</>)
CACHE_DIR
)
$
fromOk
fs
|
length
fs
<
CACHE_SIZE
=
w
#
(
infos
,
w
)
=
seqList
(
map
(\
f
st
->
let
(
i
,
w
)
=
getFileInfo
f
st
in
((
f
,
i
),
w
))
fs
)
w
|
any
(
isError
o
snd
)
infos
=
w
#
infos
=
map
(
appSnd
fromOk
)
infos
#
infos
=
sortBy
(\(_,
a
)
(_,
b
)
->
usedLess
a
b
)
infos
=
snd
$
deleteFile
(
fst
$
hd
infos
)
w
where
usedLess
::
FileInfo
FileInfo
->
Bool
usedLess
a
b
=
a
.
lastAccessedTime
<
b
.
lastAccessedTime
instance
<
Tm
where
(<)
a
b
=
[
a
.
year
,
a
.
yday
,
a
.
hour
,
a
.
min
,
a
.
sec
]
<
[
b
.
year
,
b
.
yday
,
b
.
hour
,
b
.
min
,
b
.
sec
]
writeCache
k
v
=
snd
o
writeFile
(
toCacheFile
k
)
(
toString
$
toJSON
v
)
docker-compose.yml
View file @
2ae3bdee
...
...
@@ -40,3 +40,9 @@ services:
MYSQL_DATABASE
:
cloogledb
MYSQL_USER
:
cloogle
MYSQL_PASSWORD
:
cloogle
gc
:
build
:
gc
volumes
:
-
"
./cache:/var/cache"
restart
:
always
gc/Dockerfile
0 → 100644
View file @
2ae3bdee
FROM
bash
COPY
gc.sh /
CMD
["bash", "/gc.sh"]
gc/gc.sh
0 → 100755
View file @
2ae3bdee
#!/usr/bin/env bash
CACHE_SIZE
=
1000
INTERVAL
=
600
CACHE_DIR
=
/var/cache
cd
"
$CACHE_DIR
"
while
:
;
do
n
=
"
$((
$(
ls
-l
|
wc
-l
)
-
1
))
"
if
[
"
$n
"
-gt
"
$CACHE_SIZE
"
]
;
then
ls
-1tu
|
tail
-n
"
$((
n-CACHE_SIZE
))
"
| xargs
-n1
rm
-v
else
echo
"
$n
/
$CACHE_SIZE
cache entries used"
fi
sleep
$INTERVAL
done
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