func NewRouter(maxCacheItems int) *Router { this := new(Router) this.cache = cache.NewLruCache(maxCacheItems) this.Peers = make(map[string]*Peer) return this }
package engine import ( "errors" "time" "github.com/nicholaskh/golib/cache" "github.com/nicholaskh/golib/str" log "github.com/nicholaskh/log4go" "github.com/nicholaskh/pushd/db" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" ) var ( loginUsers *cache.LruCache = cache.NewLruCache(200000) //username => 1 ) //Auth for client func authClient(token string) (string, error) { var result interface{} db.MgoSession().SetMode(mgo.Monotonic, true) _, err := db.MgoSession().DB("pushd").C("token").Find(bson.M{"tk": token}).Select(bson.M{"_id": 0, "tk": 1}).Apply(mgo.Change{Remove: true}, &result) if err == mgo.ErrNotFound { return "", errors.New("Client auth fail") } else if err != nil { log.Error("get token from db error: %s", err.Error()) return "", errors.New("Client auth fail") } return "Client auth succeed", nil
func NewPubsubChannels(maxChannelItems int) (this *PubsubChans) { this = new(PubsubChans) this.LruCache = cache.NewLruCache(maxChannelItems) return }