work in progress
This commit is contained in:
parent
38f7c31517
commit
07ff5ccffb
23 changed files with 228 additions and 240 deletions
9
pkg/cache/cache.go
vendored
9
pkg/cache/cache.go
vendored
|
|
@ -1,12 +1,13 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CachedPage struct {
|
||||
Page *Page
|
||||
Page *core.Page
|
||||
CacheTime time.Time
|
||||
}
|
||||
|
||||
|
|
@ -19,12 +20,12 @@ func NewCache() *Cache {
|
|||
return &Cache{Cache: make(map[string]*CachedPage)}
|
||||
}
|
||||
|
||||
func (c *Cache) Add(title string, p *Page) {
|
||||
func (c *Cache) Add(title string, p *core.Page) {
|
||||
now := time.Now()
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
cp, ok := c.Cache[title]
|
||||
if ok && now.After(c.CacheTime) {
|
||||
if ok && now.After(cp.CacheTime) {
|
||||
cp.Page = p
|
||||
cp.CacheTime = now
|
||||
c.Cache[title] = cp
|
||||
|
|
@ -33,7 +34,7 @@ func (c *Cache) Add(title string, p *Page) {
|
|||
c.Cache[title] = &CachedPage{p, now}
|
||||
}
|
||||
|
||||
func (c *Cache) Get(title string) *Page {
|
||||
func (c *Cache) Get(title string) *core.Page {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
if cp, ok := c.Cache[title]; ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue