entity

package
v0.0.0-...-4ecf446 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2019 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntityCollectionName = "default_entities"
)

Entities constants

Variables

This section is empty.

Functions

func DefaultCollection

func DefaultCollection(session *mgo.Session) mongo.Collection

DefaultCollection returns the default mongo collection for entities

func NewCache

func NewCache(redis *redis.Client) cache.Cache

NewCache creates the local cache and remote cache access for entitys.

Types

type Adapter

type Adapter interface {
	Insert(entity types.Entity) error

	Update(entity types.Entity) error

	Remove(entity types.Entity) error

	BulkInsert(types.Entity) error

	BulkUpdate(types.Entity) error

	FlushBulk() error

	FlushBulkInsert() error

	FlushBulkUpdate() error

	Get(id string) (types.Entity, bool)

	GetIDs(filter bson.M, ids *[]interface{}) error

	GetEntityByID(id string) (types.Entity, error)

	Count() (int, error)

	RemoveAll() error
}

Adapter ...

func NewAdapter

func NewAdapter(collection mongo.Collection) Adapter

NewAdapter gives the correct entity adapter. Give nil to the redis client and it will create a new redis.Client with the dedicated redis database for entities.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache ...

func (Cache) Drop

func (c Cache) Drop(ids ...string) error

Drop entities in local and remote cache. Use Entity.ID for ids.

func (Cache) Flush

func (c Cache) Flush() error

Flush entity cache

func (*Cache) Get

func (c *Cache) Get(id string, out interface{}) bool

Get entity from cache if it exists. Returns the entity, true or entity, false

func (Cache) Set

func (c Cache) Set(entity cache.Cacheable) error

Set the local and remote cache with this entity. If entity is nil, only the local cache is set with this value.

func (*Cache) SetRaw

func (c *Cache) SetRaw(id string, entity interface{}) error

SetRaw is not implemented. Will panic.

type Service

type Service interface {
	Adapter

	FlushCache() error
}

Service glue Adapter and Cache together

func NewService

func NewService(adapter Adapter, cache cache.Cache) Service

NewService makes calls to cache and adapter to manipulate entities

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL