-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8488ca4
commit a18b70f
Showing
6 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div class="mollitia-playground"> | ||
<Circuit ref="c1" :modules="modules" @end="onCircuitEnd" :can-fail="false"> | ||
<Cache ref="ca1"></Cache> | ||
</Circuit> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Circuit from '../../Circuit'; | ||
import Cache from '../../module/Cache'; | ||
export default { | ||
name: 'pg-cache', | ||
components: { | ||
Circuit, | ||
Cache | ||
}, | ||
data () { | ||
return { | ||
modules: [] | ||
}; | ||
}, | ||
methods: { | ||
onCircuitEnd () { | ||
this.$refs.ca1.onEnd(); | ||
} | ||
}, | ||
mounted () { | ||
this.modules.push(this.$refs.ca1.cache); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
div.mollitia-playground { | ||
height: 100%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<template> | ||
<div class="mollitia-module-cache"> | ||
<div class="mollitia-module-cache-header"> | ||
<div>{{ name }}</div> | ||
</div> | ||
<div class="mollitia-module-cache-content"> | ||
<div class="mollitia-module-cache-config"> | ||
<div>TTL: <input v-model.number="ttl" @input="update" type="number"/></div> | ||
</div> | ||
<div class="mollitia-module-cache-visual"> | ||
<div class="mollitia-module-cache-time"> | ||
<div class="mollitia-module-cache-time-progress" :style="timeStyle"></div> | ||
</div> | ||
<div class="mollitia-module-cache-percentage"> | ||
<div class="mollitia-module-cache-title">Cache Duration</div> | ||
<div class="mollitia-module-cache-percentage-progress" :style="style"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Cache', | ||
props: { | ||
name: { | ||
type: String, | ||
default: 'Cache' | ||
} | ||
}, | ||
data () { | ||
return { | ||
cache: null, | ||
ttl: 10000, | ||
timePercent: 0, | ||
percent: 0, | ||
timeInterval: null, | ||
interval: null, | ||
cached: false | ||
}; | ||
}, | ||
computed: { | ||
time () { | ||
return this.$parent.time; | ||
}, | ||
width () { | ||
return; | ||
}, | ||
timeStyle () { | ||
return { | ||
'width': `${this.timePercent}%` | ||
} | ||
}, | ||
style () { | ||
return { | ||
'width': `${this.percent}%`, | ||
'background-color': this.cached ? 'var(--mollitia-success-color)' : 'var(--mollitia-error-color)' | ||
} | ||
} | ||
}, | ||
methods: { | ||
update () { | ||
this.cache.ttl = this.ttl; | ||
}, | ||
onExecute () { | ||
// Time | ||
this.timePercent = 0; | ||
this.timeInterval = setInterval(() => { | ||
this.timePercent += (100 * 100 / this.time); | ||
if (this.timePercent >= 100) { | ||
clearInterval(this.timeInterval); | ||
} | ||
}, 100); | ||
}, | ||
onEnd () { | ||
this.failed = false; | ||
this.timePercent = 100; | ||
clearInterval(this.timeInterval); | ||
// Cache | ||
if (!this.interval) { | ||
this.cached = true; | ||
this.percent = 0; | ||
this.interval = setInterval(() => { | ||
this.percent += (100 * 100 / this.ttl); | ||
if (this.percent >= 100) { | ||
this.cached = false; | ||
clearInterval(this.interval); | ||
this.interval = null; | ||
} | ||
}, 100); | ||
} | ||
} | ||
}, | ||
created () { | ||
this.cache = new this.$mollitia.Cache({ | ||
ttl: this.ttl, | ||
logger: { | ||
debug: this.$parent.log | ||
} | ||
}); | ||
this.cache.on('execute', this.onExecute); | ||
}, | ||
destroyed () { | ||
clearInterval(this.timeInterval); | ||
clearInterval(this.interval); | ||
this.cache.off('execute', this.onExecute); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
div.mollitia-module-cache { | ||
border: 1px solid var(--madoc-grey-5); | ||
> div.mollitia-module-cache-header { | ||
padding: 10px; | ||
border-bottom: 1px solid var(--madoc-grey-5); | ||
} | ||
> div.mollitia-module-cache-content { | ||
display: flex; | ||
> div.mollitia-module-cache-config { | ||
padding: 10px; | ||
border-right: 1px solid var(--madoc-grey-5); | ||
} | ||
> div.mollitia-module-cache-visual { | ||
flex-grow: 1; | ||
display: flex; | ||
flex-direction: column; | ||
min-height: 50px; | ||
> div.mollitia-module-cache-time { | ||
height: 50%; | ||
> div.mollitia-module-cache-time-progress { | ||
background-color: var(--mollitia-info-color); | ||
height: 100%; | ||
transition: | ||
width .25s ease, | ||
background-color .25s ease; | ||
} | ||
} | ||
> div.mollitia-module-cache-percentage { | ||
position: relative; | ||
height: 50%; | ||
> div.mollitia-module-cache-title { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
> div.mollitia-module-cache-percentage-progress { | ||
height: 100%; | ||
transition: | ||
width .25s ease, | ||
background-color .25s ease; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: Mollitia - API - Module - Cache | ||
--- | ||
# Cache | ||
|
||
<pg-cache></pg-cache> | ||
|
||
## Usage | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters