Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
965 B

package main
import (
"database/sql"
)
func (db *database) cachePersistently(key string, data []byte) error {
_, err := db.exec("insert or replace into persistent_cache(key, data, date) values(@key, @data, @date)", sql.Named("key", key), sql.Named("data", data), sql.Named("date", utcNowString()))
return err
}
func (db *database) retrievePersistentCache(key string) (data []byte, err error) {
d, err, _ := db.pc.Do(key, func() (interface{}, error) {
if row, err := db.queryRow("select data from persistent_cache where key = @key", sql.Named("key", key)); err == sql.ErrNoRows {
return nil, nil
} else if err != nil {
return nil, err
} else {
err = row.Scan(&data)
return data, err
}
})
if err != nil {
return nil, err
}
return d.([]byte), nil
}
func (db *database) clearPersistentCache(pattern string) error {
_, err := db.exec("delete from persistent_cache where key like @pattern", sql.Named("pattern", pattern))
return err
}