@@ -11,26 +11,28 @@ import (
11
11
12
12
const (
13
13
// CachePrefix is the prefix for all keys in authz cache
14
- CachePrefix = "authz"
15
- objTypePrefix = "OBJTYPE" // Primary key for object type
16
- objTypeCollectionKeyString = "OBJTYPE_COL" // Global collection for object type
17
- edgeTypePrefix = "EDGETYPE" // Primary key for edge type
18
- edgeTypeCollectionKeyString = "EDGETYPE_COL" // Global collection for edge type
19
- objPrefix = "OBJ" // Primary key for object
20
- objCollectionKeyString = "OBJ_COL" // Global collection for object
21
- objEdgeCollection = "OBJEDGES" // Per object collection of all in/out edges
22
- perObjectEdgesPrefix = "E" // Per object collection of source/target edges
23
- perObjectPathPrefix = "P" // Per object collection containing path for a particular source/target/attribute
24
- edgePrefix = "EDGE" // Primary key for edge
25
- edgeCollectionKeyString = "EDGE_COL" // Global collection for edge
26
- orgPrefix = "ORG" // Primary key for organization
27
- orgCollectionKeyString = "ORG_COL" // Global collection for organizations
28
- dependencyPrefix = "DEP" // Shared dependency key prefix among all items
29
- isModifiedPrefix = "MOD" // Shared is modified key prefix among all items
14
+ CachePrefix = "authz"
15
+ objTypePrefix = "OBJTYPE" // Primary key for object type
16
+ objTypeCollectionKeyString = "OBJTYPE_COL" // Global collection for object type
17
+ edgeTypePrefix = "EDGETYPE" // Primary key for edge type
18
+ edgeTypeCollectionKeyString = "EDGETYPE_COL" // Global collection for edge type
19
+ objPrefix = "OBJ" // Primary key for object
20
+ objCollectionKeyString = "OBJ_COL" // Global collection for object
21
+ objEdgeCollection = "OBJEDGES" // Per object collection of all in/out edges
22
+ perObjectEdgesPrefix = "E" // Per object collection of source/target edges
23
+ perObjectPathPrefix = "P" // Per object collection containing path for a particular source/target/attribute
24
+ edgePrefix = "EDGE" // Primary key for edge
25
+ edgeCollectionKeyString = "EDGE_COL" // Global collection for edge
26
+ edgeCollectionPagesPrefixString = "PAGES" // Pages making up global collection of edges
27
+ orgPrefix = "ORG" // Primary key for organization
28
+ orgCollectionKeyString = "ORG_COL" // Global collection for organizations
29
+ dependencyPrefix = "DEP" // Shared dependency key prefix among all items
30
+ isModifiedPrefix = "MOD" // Shared is modified key prefix among all items
30
31
)
31
32
32
33
// CacheNameProvider is the base implementation of the CacheNameProvider interface
33
34
type CacheNameProvider struct {
35
+ cache.NoRateLimitKeyNameProvider
34
36
basePrefix string // Base prefix for all keys TenantID_OrgID
35
37
}
36
38
@@ -73,6 +75,8 @@ const (
73
75
DependencyKeyID = "DependencyKeyID"
74
76
// IsModifiedKeyID is the key value indicating change in last TTL
75
77
IsModifiedKeyID = "IsModifiedKeyID"
78
+ // IsModifiedCollectionKeyID is the key value indicating change for global colleciton in last TTL
79
+ IsModifiedCollectionKeyID = "IsModifiedCollectionKeyID"
76
80
// ObjectTypeCollectionKeyID is the key for global collection of object types
77
81
ObjectTypeCollectionKeyID = "ObjTypeCollectionKeyID"
78
82
// EdgeTypeCollectionKeyID is the key for global collection of edge types
@@ -81,6 +85,10 @@ const (
81
85
ObjectCollectionKeyID = "ObjCollectionKeyID"
82
86
// EdgeCollectionKeyID is the key for global collection of edges
83
87
EdgeCollectionKeyID = "EdgeCollectionKeyID"
88
+ // EdgeCollectionPagesKeyID is the key for pages making up global collection of edges
89
+ EdgeCollectionPagesKeyID = "EdgeCollectionPagesKeyID"
90
+ // EdgeCollectionPageKeyID is the key for each individual page in the global collection of edges
91
+ EdgeCollectionPageKeyID = "EdgeCollectionPageKeyID"
84
92
// OrganizationCollectionKeyID is the key for global collection of organizations
85
93
OrganizationCollectionKeyID = "OrgCollectionKeyID"
86
94
// AttributePathObjToObjID is the primary key for attribute path
@@ -109,10 +117,13 @@ func (c *CacheNameProvider) GetAllKeyIDs() []string {
109
117
EdgesObjToObjID ,
110
118
DependencyKeyID ,
111
119
IsModifiedKeyID ,
120
+ IsModifiedCollectionKeyID ,
112
121
ObjectTypeCollectionKeyID ,
113
122
EdgeTypeCollectionKeyID ,
114
123
ObjectCollectionKeyID ,
115
124
EdgeCollectionKeyID ,
125
+ EdgeCollectionPagesKeyID ,
126
+ EdgeCollectionPageKeyID ,
116
127
OrganizationCollectionKeyID ,
117
128
AttributePathObjToObjID ,
118
129
}
@@ -165,6 +176,10 @@ func (c *CacheNameProvider) GetKeyName(id cache.KeyNameID, components []string)
165
176
return c .objCollectionKey ()
166
177
case EdgeCollectionKeyID :
167
178
return c .edgeCollectionKey ()
179
+ case EdgeCollectionPagesKeyID :
180
+ return c .edgeCollectionPagesKey ()
181
+ case EdgeCollectionPageKeyID :
182
+ return c .edgeCollectionPageKey (components [0 ], components [1 ])
168
183
case OrganizationCollectionKeyID :
169
184
return c .orgCollectionKey ()
170
185
case ObjEdgesKeyID :
@@ -173,6 +188,8 @@ func (c *CacheNameProvider) GetKeyName(id cache.KeyNameID, components []string)
173
188
return c .dependencyKey (components [0 ])
174
189
case IsModifiedKeyID :
175
190
return c .isModifiedKey (components [0 ])
191
+ case IsModifiedCollectionKeyID :
192
+ return c .isModifiedCollectionKey (components [0 ])
176
193
case EdgeFullKeyID :
177
194
return c .edgeFullKeyNameFromIDs (components [0 ], components [1 ], components [2 ])
178
195
case AttributePathObjToObjID :
@@ -271,6 +288,20 @@ func (c *CacheNameProvider) edgeCollectionKey() cache.Key {
271
288
return cache .Key (fmt .Sprintf ("%v_%v" , c .basePrefix , edgeCollectionKeyString ))
272
289
}
273
290
291
+ // edgeCollectionModifiedKey returns key name for edge collection
292
+ func (c * CacheNameProvider ) isModifiedCollectionKey (colKey string ) cache.Key {
293
+ return cache .Key (fmt .Sprintf ("%v_%v" , colKey , isModifiedPrefix ))
294
+ }
295
+
296
+ // edgeCollectionKey returns key name for edge collection
297
+ func (c * CacheNameProvider ) edgeCollectionPagesKey () cache.Key {
298
+ return cache .Key (fmt .Sprintf ("%v_%v_%v" , c .basePrefix , edgeCollectionKeyString , edgeCollectionPagesPrefixString ))
299
+ }
300
+
301
+ func (c * CacheNameProvider ) edgeCollectionPageKey (cursor string , limit string ) cache.Key {
302
+ return cache .Key (fmt .Sprintf ("%v_%v_%v_%v" , c .basePrefix , edgeCollectionKeyString , cursor , limit ))
303
+ }
304
+
274
305
// orgCollectionKey returns key name for edge collection
275
306
func (c * CacheNameProvider ) orgCollectionKey () cache.Key {
276
307
return cache .Key (fmt .Sprintf ("%v_%v" , c .basePrefix , orgCollectionKeyString ))
@@ -291,6 +322,11 @@ func (ot ObjectType) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
291
322
return c .GetKeyNameStatic (ObjectTypeCollectionKeyID )
292
323
}
293
324
325
+ // GetGlobalCollectionPagesKey returns the global collection key name for object type
326
+ func (ot ObjectType ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
327
+ return "" // Unused since there is no pagination for object types
328
+ }
329
+
294
330
// GetSecondaryKeys returns the secondary cache key names for object type
295
331
func (ot ObjectType ) GetSecondaryKeys (c cache.KeyNameProvider ) []cache.Key {
296
332
return []cache.Key {c .GetKeyNameWithString (ObjectTypeNameKeyID , ot .TypeName )}
@@ -311,6 +347,11 @@ func (ot ObjectType) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
311
347
return c .GetKeyNameWithID (IsModifiedKeyID , ot .ID )
312
348
}
313
349
350
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for object type
351
+ func (ot ObjectType ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
352
+ return "" // Unused until we turn one page caching
353
+ }
354
+
314
355
// GetDependencyKeys returns the list of keys for object type dependencies
315
356
func (ot ObjectType ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
316
357
return []cache.Key {} // ObjectTypes don't depend on anything
@@ -331,6 +372,11 @@ func (et EdgeType) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
331
372
return c .GetKeyNameStatic (EdgeTypeCollectionKeyID )
332
373
}
333
374
375
+ // GetGlobalCollectionPagesKey returns the global collection key name for edge type
376
+ func (et EdgeType ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
377
+ return "" // Unused since there is no pagination for edge types
378
+ }
379
+
334
380
// GetPerItemCollectionKey returns the per item collection key name for edge type
335
381
func (et EdgeType ) GetPerItemCollectionKey (c cache.KeyNameProvider ) cache.Key {
336
382
return "" // Unused since there nothing stored per edge type, could store edges of this type in the future
@@ -351,6 +397,11 @@ func (et EdgeType) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
351
397
return c .GetKeyNameWithID (IsModifiedKeyID , et .ID )
352
398
}
353
399
400
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for edge type
401
+ func (et EdgeType ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
402
+ return "" // Unused until we turn one page caching
403
+ }
404
+
354
405
// GetDependencyKeys returns the list of keys for edge type dependencies
355
406
func (et EdgeType ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
356
407
// EdgeTypes depend on source/target object types but we don't store that dependency because we currently flush the whole cache on object type delete
@@ -380,6 +431,11 @@ func (o Object) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
380
431
return c .GetKeyNameStatic (ObjectCollectionKeyID )
381
432
}
382
433
434
+ // GetGlobalCollectionPagesKey returns the global collection key name for objects
435
+ func (o Object ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
436
+ return "" // Unused since there is no pagination for objects
437
+ }
438
+
383
439
// GetPerItemCollectionKey returns the per item collection key name for object
384
440
func (o Object ) GetPerItemCollectionKey (c cache.KeyNameProvider ) cache.Key {
385
441
return c .GetKeyNameWithID (ObjEdgesKeyID , o .ID )
@@ -395,6 +451,11 @@ func (o Object) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
395
451
return c .GetKeyNameWithID (IsModifiedKeyID , o .ID )
396
452
}
397
453
454
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for object
455
+ func (o Object ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
456
+ return "" // Unused until we turn one page caching
457
+ }
458
+
398
459
// GetDependencyKeys returns the list of keys for object dependencies
399
460
func (o Object ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
400
461
// Objects depend on object types but we don't store that dependency because we currently flush the whole cache on object type delete
@@ -416,6 +477,11 @@ func (e Edge) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
416
477
return c .GetKeyNameStatic (EdgeCollectionKeyID )
417
478
}
418
479
480
+ // GetGlobalCollectionPagesKey returns the global collection key name for edge
481
+ func (e Edge ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
482
+ return c .GetKeyNameStatic (EdgeCollectionPagesKeyID )
483
+ }
484
+
419
485
// GetPerItemCollectionKey returns the per item collection key name for edge
420
486
func (e Edge ) GetPerItemCollectionKey (c cache.KeyNameProvider ) cache.Key {
421
487
return ""
@@ -431,6 +497,11 @@ func (e Edge) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
431
497
return c .GetKeyNameWithID (IsModifiedKeyID , e .ID )
432
498
}
433
499
500
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for edge
501
+ func (e Edge ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
502
+ return c .GetKeyNameWithString (IsModifiedCollectionKeyID , string (e .GetGlobalCollectionKey (c )))
503
+ }
504
+
434
505
// GetDependencyKeys returns the list of keys for edge dependencies
435
506
func (e Edge ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
436
507
// Edges depend on objects and edge types. We don't store edgetype dependency because we currently flush the whole cache on edge type delete
@@ -447,7 +518,7 @@ func (e Edge) TTL(c cache.TTLProvider) time.Duration {
447
518
return c .TTL (EdgeTTL )
448
519
}
449
520
450
- // GetPrimaryKey returns the primary cache key name for edge
521
+ // GetPrimaryKey returns the primary cache key name for path node
451
522
func (e AttributePathNode ) GetPrimaryKey (c cache.KeyNameProvider ) cache.Key {
452
523
return "" // Unused since AttributePathNode is not stored in cache directly
453
524
}
@@ -457,6 +528,11 @@ func (e AttributePathNode) GetGlobalCollectionKey(c cache.KeyNameProvider) cache
457
528
return ""
458
529
}
459
530
531
+ // GetGlobalCollectionPagesKey returns the global collection key name for path node
532
+ func (e AttributePathNode ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
533
+ return "" // Unused since there is no pagination for path node
534
+ }
535
+
460
536
// GetPerItemCollectionKey returns the per item collection key name for path node
461
537
func (e AttributePathNode ) GetPerItemCollectionKey (c cache.KeyNameProvider ) cache.Key {
462
538
return ""
@@ -472,6 +548,11 @@ func (e AttributePathNode) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
472
548
return ""
473
549
}
474
550
551
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for attribute path
552
+ func (e AttributePathNode ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
553
+ return "" // Unused until we turn one page caching
554
+ }
555
+
475
556
// GetDependencyKeys returns the list of keys for path node dependencies
476
557
func (e AttributePathNode ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
477
558
// Path node depend on objects and edges.
@@ -501,6 +582,11 @@ func (o Organization) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key
501
582
return c .GetKeyNameStatic (OrganizationCollectionKeyID )
502
583
}
503
584
585
+ // GetGlobalCollectionPagesKey returns the global collection key name for organization
586
+ func (o Organization ) GetGlobalCollectionPagesKey (c cache.KeyNameProvider ) cache.Key {
587
+ return "" // Unused since there is no pagination for organization
588
+ }
589
+
504
590
// GetPerItemCollectionKey returns the per item collection key name for organization (none)
505
591
func (o Organization ) GetPerItemCollectionKey (c cache.KeyNameProvider ) cache.Key {
506
592
return ""
@@ -516,6 +602,11 @@ func (o Organization) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
516
602
return c .GetKeyNameWithID (IsModifiedKeyID , o .ID )
517
603
}
518
604
605
+ // GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for organization
606
+ func (o Organization ) GetIsModifiedCollectionKey (c cache.KeyNameProvider ) cache.Key {
607
+ return "" // Unused until we turn one page caching
608
+ }
609
+
519
610
// GetDependencyKeys returns the list of keys for organization dependencies
520
611
func (o Organization ) GetDependencyKeys (c cache.KeyNameProvider ) []cache.Key {
521
612
return []cache.Key {}
0 commit comments