Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12686805
cache.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
944 B
Subscribers
None
cache.go
View Options
package
writefreely
import
(
"sync"
"time"
)
const
(
postsCacheTime
=
4
*
time
.
Second
)
type
(
postsCacheItem
struct
{
Expire
time
.
Time
Posts
*
[]
PublicPost
ready
chan
struct
{}
}
AuthCache
struct
{
Alias
,
Pass
,
Token
string
BadPasses
map
[
string
]
bool
expire
time
.
Time
}
)
var
(
userPostsCache
=
struct
{
sync
.
RWMutex
users
map
[
int64
]
postsCacheItem
}{
users
:
map
[
int64
]
postsCacheItem
{},
}
)
func
CachePosts
(
userID
int64
,
p
*
[]
PublicPost
)
{
close
(
userPostsCache
.
users
[
userID
].
ready
)
userPostsCache
.
Lock
()
userPostsCache
.
users
[
userID
]
=
postsCacheItem
{
Expire
:
time
.
Now
().
Add
(
postsCacheTime
),
Posts
:
p
,
}
userPostsCache
.
Unlock
()
}
func
GetPostsCache
(
userID
int64
)
*
[]
PublicPost
{
userPostsCache
.
RLock
()
pci
,
ok
:=
userPostsCache
.
users
[
userID
]
userPostsCache
.
RUnlock
()
if
!
ok
{
return
nil
}
if
pci
.
Expire
.
Before
(
time
.
Now
())
{
// Cache is expired
return
nil
}
return
pci
.
Posts
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 13, 11:03 PM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3519408
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment