mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-04 14:12:24 -06:00
Database updates (#144)
* start moving some database stuff around * continue moving db stuff around * more fiddling * more updates * and some more * and yet more * i broke SOMETHING but what, it's a mystery * tidy up * vendor ttlcache * use ttlcache * fix up some tests * rename some stuff * little reminder * some more updates
This commit is contained in:
parent
ce190d867c
commit
4920229a3b
164 changed files with 4850 additions and 2617 deletions
46
vendor/github.com/ReneKroon/ttlcache/item.go
generated
vendored
Normal file
46
vendor/github.com/ReneKroon/ttlcache/item.go
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package ttlcache
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// ItemNotExpire Will avoid the item being expired by TTL, but can still be exired by callback etc.
|
||||
ItemNotExpire time.Duration = -1
|
||||
// ItemExpireWithGlobalTTL will use the global TTL when set.
|
||||
ItemExpireWithGlobalTTL time.Duration = 0
|
||||
)
|
||||
|
||||
func newItem(key string, data interface{}, ttl time.Duration) *item {
|
||||
item := &item{
|
||||
data: data,
|
||||
ttl: ttl,
|
||||
key: key,
|
||||
}
|
||||
// since nobody is aware yet of this item, it's safe to touch without lock here
|
||||
item.touch()
|
||||
return item
|
||||
}
|
||||
|
||||
type item struct {
|
||||
key string
|
||||
data interface{}
|
||||
ttl time.Duration
|
||||
expireAt time.Time
|
||||
queueIndex int
|
||||
}
|
||||
|
||||
// Reset the item expiration time
|
||||
func (item *item) touch() {
|
||||
if item.ttl > 0 {
|
||||
item.expireAt = time.Now().Add(item.ttl)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify if the item is expired
|
||||
func (item *item) expired() bool {
|
||||
if item.ttl <= 0 {
|
||||
return false
|
||||
}
|
||||
return item.expireAt.Before(time.Now())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue