Rewrote cache implemenation.
This commit is contained in:
parent
ab55705b9f
commit
3f46617f80
7 changed files with 285 additions and 148 deletions
|
|
@ -117,10 +117,12 @@ func (c *Container) initWeb() {
|
|||
|
||||
// initCache initializes the cache
|
||||
func (c *Container) initCache() {
|
||||
var err error
|
||||
if c.Cache, err = NewCacheClient(c.Config); err != nil {
|
||||
store, err := newInMemoryCache(c.Config.Cache.Capacity)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.Cache = NewCacheClient(store)
|
||||
}
|
||||
|
||||
// initDatabase initializes the database
|
||||
|
|
@ -142,24 +144,6 @@ func (c *Container) initDatabase() {
|
|||
}
|
||||
}
|
||||
|
||||
func openDB(driver, connection string) (*sql.DB, error) {
|
||||
// Helper to automatically create the directories that the specific sqlite file
|
||||
// should reside in
|
||||
if driver == "sqlite3" {
|
||||
d := strings.Split(connection, "/")
|
||||
|
||||
if len(d) > 1 {
|
||||
path := strings.Join(d[:len(d)-1], "/")
|
||||
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sql.Open(driver, connection)
|
||||
}
|
||||
|
||||
// initORM initializes the ORM
|
||||
func (c *Container) initORM() {
|
||||
drv := entsql.OpenDB(c.Config.Database.Driver, c.Database)
|
||||
|
|
@ -198,3 +182,22 @@ func (c *Container) initTasks() {
|
|||
panic(fmt.Sprintf("failed to create task client: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// openDB opens a database connection
|
||||
func openDB(driver, connection string) (*sql.DB, error) {
|
||||
// Helper to automatically create the directories that the specified sqlite file
|
||||
// should reside in, if one
|
||||
if driver == "sqlite3" {
|
||||
d := strings.Split(connection, "/")
|
||||
|
||||
if len(d) > 1 {
|
||||
path := strings.Join(d[:len(d)-1], "/")
|
||||
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sql.Open(driver, connection)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue