Skip to content

Commit 27894c6

Browse files
committed
started to implement the new Cache
1 parent 04cc64a commit 27894c6

File tree

3 files changed

+127
-263
lines changed

3 files changed

+127
-263
lines changed

engine/cache/cache.go

Lines changed: 125 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,133 @@
55
package cache
66

77
import (
8+
"errors"
9+
"sync"
10+
"time"
11+
12+
assetdb "github.com/owasp-amass/asset-db"
13+
"github.com/owasp-amass/asset-db/repository"
14+
"github.com/owasp-amass/asset-db/repository/sqlrepo"
815
"github.com/owasp-amass/asset-db/types"
916
oam "github.com/owasp-amass/open-asset-model"
1017
)
1118

12-
type Cache interface {
13-
GetAsset(a oam.Asset) (*types.Asset, bool)
14-
GetAssetsByType(t oam.AssetType) ([]*types.Asset, bool)
15-
SetAsset(a *types.Asset)
16-
GetRelations(r *types.Relation) ([]*types.Relation, bool)
17-
GetRelationsByType(rtype string) ([]*types.Relation, bool)
18-
GetIncomingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, bool)
19-
GetOutgoingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, bool)
20-
SetRelation(r *types.Relation)
21-
Close()
19+
type Cache struct {
20+
sync.Mutex
21+
cache repository.Repository
22+
db repository.Repository
23+
}
24+
25+
func New(database repository.Repository) (repository.Repository, error) {
26+
if c := assetdb.New(sqlrepo.SQLiteMemory, ""); c != nil {
27+
return &Cache{
28+
cache: c,
29+
db: database,
30+
}, nil
31+
}
32+
return nil, errors.New("failed to create the cache repository")
33+
}
34+
35+
// Close implements the Repository interface.
36+
func (c *Cache) Close() error {
37+
c.Lock()
38+
defer c.Unlock()
39+
40+
if c.cache != nil {
41+
if err := c.cache.Close(); err != nil {
42+
return err
43+
}
44+
}
45+
46+
return nil
47+
}
48+
49+
// GetDBType implements the Repository interface.
50+
func (c *Cache) GetDBType() string {
51+
return c.db.GetDBType()
52+
}
53+
54+
// CreateEntity implements the Repository interface.
55+
func (c *Cache) CreateEntity(asset oam.Asset) (*types.Entity, error) {
56+
57+
}
58+
59+
// UpdateEntityLastSeen implements the Repository interface.
60+
func (c *Cache) UpdateEntityLastSeen(id string) error {
61+
62+
}
63+
64+
// DeleteEntity implements the Repository interface.
65+
func (c *Cache) DeleteEntity(id string) error {
66+
67+
}
68+
69+
// DeleteEdge implements the Repository interface.
70+
func (c *Cache) DeleteEdge(id string) error {
71+
72+
}
73+
74+
// FindEntityById implements the Repository interface.
75+
func (c *Cache) FindEntityById(id string) (*types.Entity, error) {
76+
77+
}
78+
79+
// FindEntityByContent implements the Repository interface.
80+
func (c *Cache) FindEntityByContent(asset oam.Asset, since time.Time) ([]*types.Entity, error) {
81+
82+
}
83+
84+
// FindEntitiesByType implements the Repository interface.
85+
func (c *Cache) FindEntitiesByType(atype oam.AssetType, since time.Time) ([]*types.Entity, error) {
86+
87+
}
88+
89+
// FindEntitiesByScope implements the Repository interface.
90+
func (c *Cache) FindEntitiesByScope(constraints []oam.Asset, since time.Time) ([]*types.Entity, error) {
91+
92+
}
93+
94+
// Link implements the Repository interface.
95+
func (c *Cache) Link(edge *types.Edge) (*types.Edge, error) {
96+
97+
}
98+
99+
// IncomingEdges implements the Repository interface.
100+
func (c *Cache) IncomingEdges(entity *types.Entity, since time.Time, labels ...string) ([]*types.Edge, error) {
101+
102+
}
103+
104+
// OutgoingEdges implements the Repository interface.
105+
func (c *Cache) OutgoingEdges(entity *types.Entity, since time.Time, labels ...string) ([]*types.Edge, error) {
106+
107+
}
108+
109+
// CreateEntityTag implements the Repository interface.
110+
func (c *Cache) CreateEntityTag(entity *types.Entity, property oam.Property) (*types.EntityTag, error) {
111+
112+
}
113+
114+
// GetEntityTags implements the Repository interface.
115+
func (c *Cache) GetEntityTags(entity *types.Entity, since time.Time, names ...string) ([]*types.EntityTag, error) {
116+
117+
}
118+
119+
// DeleteEntityTag implements the Repository interface.
120+
func (c *Cache) DeleteEntityTag(id string) error {
121+
122+
}
123+
124+
// CreateEdgeTag implements the Repository interface.
125+
func (c *Cache) CreateEdgeTag(edge *types.Edge, property oam.Property) (*types.EdgeTag, error) {
126+
127+
}
128+
129+
// GetEdgeTags implements the Repository interface.
130+
func (c *Cache) GetEdgeTags(edge *types.Edge, since time.Time, names ...string) ([]*types.EdgeTag, error) {
131+
132+
}
133+
134+
// DeleteEdgeTag implements the Repository interface.
135+
func (c *Cache) DeleteEdgeTag(id string) error {
136+
22137
}

engine/cache/oam_cache.go

Lines changed: 0 additions & 251 deletions
This file was deleted.

0 commit comments

Comments
 (0)