Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,21 @@ func (c *Controller) SetTypeAction(controllerName, methodName string, typeOfCont
}

if RevelConfig.Controller.Reuse {
RevelConfig.Controller.CacheMapLocked.RLock()
if _, ok := RevelConfig.Controller.CachedMap[c.Name]; !ok {
// Create a new stack for this controller
localType := c.Type.Type
RevelConfig.Controller.CacheMapLocked.RUnlock()
RevelConfig.Controller.CacheMapLocked.Lock()
defer RevelConfig.Controller.CacheMapLocked.Unlock()
RevelConfig.Controller.CachedMap[c.Name] = utils.NewStackLock(
RevelConfig.Controller.CachedStackSize,
RevelConfig.Controller.CachedStackMaxSize,
func() interface{} {
return reflect.New(localType).Interface()
})
} else {
defer RevelConfig.Controller.CacheMapLocked.RUnlock()
}
// Instantiate the controller.
c.AppController = RevelConfig.Controller.CachedMap[c.Name].Pop()
Expand Down
7 changes: 6 additions & 1 deletion model/revel_controller.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package model

import "github.com/revel/revel/utils"
import (
"sync"

"github.com/revel/revel/utils"
)

type RevelController struct {
Reuse bool // True if the controllers are reused Set via revel.controller.reuse
Stack *utils.SimpleLockStack // size set by revel.controller.stack, revel.controller.maxstack
CachedMap map[string]*utils.SimpleLockStack // The map of reusable controllers
CacheMapLocked *sync.RWMutex // A locking mechanizim to prevent concurrent writes to the cache
CachedStackSize int // The default size of each stack in CachedMap Set via revel.cache.controller.stack
CachedStackMaxSize int // The max size of each stack in CachedMap Set via revel.cache.controller.maxstack
}
2 changes: 2 additions & 0 deletions revel.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func updateLog(inputmode string) (returnMode string) {
packagePathMap[k] = v.(string)
}
}
} else {
RevelLog.Warn("Failed to unpack json file", "error", err, "Json", inputmode)
Comment on lines +232 to +233
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not raise a warning here. Because it said "The input mode can be as simple as "prod" or it can be a JSON string" before. This code should be removed.

}

var newContext *config.Context
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"strconv"
"strings"
"sync"

"github.com/revel/revel/session"
"github.com/revel/revel/utils"
Expand Down Expand Up @@ -146,6 +147,7 @@ func initControllerStack() {
RevelConfig.Controller.CachedStackSize = Config.IntDefault("revel.cache.controller.stack", 10)
RevelConfig.Controller.CachedStackMaxSize = Config.IntDefault("revel.cache.controller.maxstack", 100)
RevelConfig.Controller.CachedMap = map[string]*utils.SimpleLockStack{}
RevelConfig.Controller.CacheMapLocked = &sync.RWMutex{}
}
}

Expand Down