1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
11 "github.com/revel/revel"
14 var cacheLog = revel.RevelLog.New("section", "cache")
17 revel.OnAppStart(func() {
18 // Set the default expiration time.
19 defaultExpiration := time.Hour // The default for the default is one hour.
20 if expireStr, found := revel.Config.String("cache.expires"); found {
22 if defaultExpiration, err = time.ParseDuration(expireStr); err != nil {
23 cacheLog.Panic("Could not parse default cache expiration duration " + expireStr + ": " + err.Error())
27 // make sure you aren't trying to use both memcached and redis
28 if revel.Config.BoolDefault("cache.memcached", false) && revel.Config.BoolDefault("cache.redis", false) {
29 cacheLog.Panic("You've configured both memcached and redis, please only include configuration for one cache!")
33 if revel.Config.BoolDefault("cache.memcached", false) {
34 hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
36 cacheLog.Panic("Memcache enabled but no memcached hosts specified!")
39 Instance = NewMemcachedCache(hosts, defaultExpiration)
43 // Use Redis (share same config as memcached)?
44 if revel.Config.BoolDefault("cache.redis", false) {
45 hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
47 cacheLog.Panic("Redis enabled but no Redis hosts specified!")
50 cacheLog.Panic("Redis currently only supports one host!")
52 password := revel.Config.StringDefault("cache.redis.password", "")
53 Instance = NewRedisCache(hosts[0], password, defaultExpiration)
57 // By default, use the in-memory cache.
58 Instance = NewInMemoryCache(defaultExpiration)