summaryrefslogtreecommitdiffstats
path: root/app/plugin_key_value_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/plugin_key_value_store.go')
-rw-r--r--app/plugin_key_value_store.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/plugin_key_value_store.go b/app/plugin_key_value_store.go
index 8c3e1f18b..f0aed31f0 100644
--- a/app/plugin_key_value_store.go
+++ b/app/plugin_key_value_store.go
@@ -19,10 +19,20 @@ func getKeyHash(key string) string {
}
func (a *App) SetPluginKey(pluginId string, key string, value []byte) *model.AppError {
+ return a.SetPluginKeyWithExpiry(pluginId, key, value, 0)
+}
+
+func (a *App) SetPluginKeyWithExpiry(pluginId string, key string, value []byte, expireInSeconds int64) *model.AppError {
+
+ if expireInSeconds > 0 {
+ expireInSeconds = model.GetMillis() + (expireInSeconds * 1000)
+ }
+
kv := &model.PluginKeyValue{
PluginId: pluginId,
Key: getKeyHash(key),
Value: value,
+ ExpireAt: expireInSeconds,
}
result := <-a.Srv.Store.Plugin().SaveOrUpdate(kv)
@@ -60,6 +70,31 @@ func (a *App) DeletePluginKey(pluginId string, key string) *model.AppError {
return result.Err
}
+func (a *App) DeleteAllKeysForPlugin(pluginId string) *model.AppError {
+ result := <-a.Srv.Store.Plugin().DeleteAllForPlugin(pluginId)
+
+ if result.Err != nil {
+ mlog.Error(result.Err.Error())
+ }
+
+ return result.Err
+}
+
+func (a *App) DeleteAllExpiredPluginKeys() *model.AppError {
+
+ if a.Srv == nil {
+ return nil
+ }
+
+ result := <-a.Srv.Store.Plugin().DeleteAllExpired()
+
+ if result.Err != nil {
+ mlog.Error(result.Err.Error())
+ }
+
+ return result.Err
+}
+
func (a *App) ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError) {
result := <-a.Srv.Store.Plugin().List(pluginId, page, perPage)