50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package main
|
|
|
|
import "federated.computer/wp-sync-slowtwitch/services/wordpress"
|
|
|
|
type AppCache struct {
|
|
UsersCache map[string]wordpress.UserData
|
|
TagCache map[string]wordpress.TagData
|
|
CategoryCache map[string]wordpress.CategoryData
|
|
}
|
|
|
|
func (appCache *AppCache) GetUser(username string) (wordpress.UserData, bool) {
|
|
user, ok := appCache.UsersCache[username]
|
|
return user, ok
|
|
}
|
|
|
|
func (appCache *AppCache) SetUser(user wordpress.UserData) {
|
|
if appCache.UsersCache == nil {
|
|
appCache.UsersCache = make(map[string]wordpress.UserData)
|
|
}
|
|
appCache.UsersCache[user.Name] = user
|
|
}
|
|
|
|
func (appCache *AppCache) GetTag(tagName string) (wordpress.TagData, bool) {
|
|
tag, ok := appCache.TagCache[tagName]
|
|
return tag, ok
|
|
}
|
|
|
|
func (appCache *AppCache) SetTag(tag wordpress.TagData) {
|
|
if appCache.TagCache == nil {
|
|
appCache.TagCache = make(map[string]wordpress.TagData)
|
|
}
|
|
appCache.TagCache[tag.Name] = tag
|
|
}
|
|
|
|
func (appCache *AppCache) GetCategory(categoryName string) (wordpress.CategoryData, bool) {
|
|
if appCache.CategoryCache != nil {
|
|
category, ok := appCache.CategoryCache[categoryName]
|
|
return category, ok
|
|
}
|
|
|
|
return wordpress.CategoryData{}, false
|
|
}
|
|
|
|
func (appCache *AppCache) SetCategory(category wordpress.CategoryData) {
|
|
if appCache.CategoryCache == nil {
|
|
appCache.CategoryCache = make(map[string]wordpress.CategoryData)
|
|
}
|
|
appCache.CategoryCache[category.Name] = category
|
|
}
|