|
|
@@ -1,10 +1,14 @@
|
|
|
package link
|
|
|
|
|
|
import (
|
|
|
+ "time"
|
|
|
+
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
"github.com/runningwater/gohub/pkg/app"
|
|
|
+ "github.com/runningwater/gohub/pkg/cache"
|
|
|
"github.com/runningwater/gohub/pkg/database"
|
|
|
+ "github.com/runningwater/gohub/pkg/helpers"
|
|
|
"github.com/runningwater/gohub/pkg/paginator"
|
|
|
)
|
|
|
|
|
|
@@ -23,6 +27,22 @@ func All() (links []Link) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func AllCached() (links []Link) {
|
|
|
+ cacheKey := "links:aa"
|
|
|
+ expireTime := 120 * time.Minute
|
|
|
+ // 获取数据
|
|
|
+ cache.GetObject(cacheKey, &links)
|
|
|
+
|
|
|
+ if helpers.Empty(links) {
|
|
|
+ links = All()
|
|
|
+ if helpers.Empty(links) {
|
|
|
+ return links
|
|
|
+ }
|
|
|
+ cache.Set(cacheKey, links, expireTime)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func IsExist(field, value string) bool {
|
|
|
var count int64
|
|
|
database.DB.Model(Link{}).Where("? = ?", field, value).Count(&count)
|