-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed API for a generic keyed cache #23
base: development
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,41 @@ | |||
# swiftclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
# keyedcache
yeah?
// | ||
func NewCache(cntxt *ReqContext, | ||
newObject func(cntxt *ReqContext, cachedObj *CachedObject) (object Object), | ||
cacheSz uint64, objectSz uint64, keySz uint64) (cache Cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are objectSz
and keySz
? How are they related to Object.SizeOf
and Key.SizeOf
?
// o Read() -- called to initialize an object when its assigned an identity; | ||
// it can block arbitrarity but cannot call into this instance of the | ||
// cache. | ||
// o Write() -- called to flush the contents of a dirty object; it can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this be named, uh, Flush() :-)
// should not call them, instead they should call methods provided by the cache | ||
// to flush or invalidate objects: | ||
// | ||
// o Read() -- called to initialize an object when its assigned an identity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a "Load()" method? Wouldn't we need to have a callback mechanism to enable the generic cache to be able to perform the type-specific "load" operation?
// o Hold() -- get an additional hold on the object | ||
// o Release() -- release a hold on the object; once all holds on an object | ||
// are released the object may be invalidated | ||
// o MarkDirty() -- mark a held object dirty; dirty objects are cleaned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we'd require a resource be "held" when calling MarkDirty()...
An alternative might be for the call to Release() to pass back an indication of "dirtiness", but this would mean others wouldn't know it was already dirty until potentially log after it was. Plus, the caller to Release() would be required to "buffer" the knowledge of dirtiness until it was ready to Release() it. I'm fine either way though.
// object can be marked dirty or flushed while multiple threads have a hold on | ||
// the object. | ||
// | ||
// A Cache provides the following methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So no "iterate through"?
I could imagine a desire to "flush everything" wanting an iterator.
Indeed, it might be interesting to iterate just over the dirty entries or just over the clean entries...
|
||
const ( | ||
INVAL_DIRTY InvalFlush = iota | ||
FLUSH_DIRTY InvalFlush = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to assume you want INVAL_DIRTY and FLUSH_DIRTY to have the same (zero) value here?
If not, I think you wanted to remove the second "= iota"... thus emulating an "enum" sequence that Go otherwise lacks.
// | ||
// The *ReqContext is passed through without using it, however the cntxt passed | ||
// to newObject() will be the cntxt passed to the call to Lookup() that | ||
// triggered object creation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are more callbacks (e.g. hash and equals) that might be useful here...
Release(cntxt *ReqContext) | ||
MarkDirty(cntxt *ReqContext) | ||
IsDirty(cntxt *ReqContext) bool | ||
Flush(cntxt *ReqContext) (err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, here is the "flush" upcall/callback... now I see...
This includes only the proposed API for a keyed cache that caches object which can be identified by keys.
At present the cache will only be used for inodes and the API includes only those operations necessary to implement a cache for inodes, not everything that one might want in a general purpose cache. (It can always be extended later.)
In particular, the cache doesn't include: