Post-Migrator/app-cache.go

50 lines
1.4 KiB
Go
Raw Normal View History

2024-05-08 00:52:47 +00:00
package main
import "federated.computer/wp-sync-slowtwitch/services/wordpress"
type AppCache struct {
2024-05-09 20:06:01 +00:00
UsersCache map[string]wordpress.UserData
TagCache map[string]wordpress.TagData
CategoryCache map[string]wordpress.CategoryData
2024-05-08 00:52:47 +00:00
}
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
}
2024-05-08 01:23:21 +00:00
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
}
2024-05-09 20:06:01 +00:00
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
}