public class InMemoryDirectoryListCache extends DirectoryListCache
This in-memory layer guarantees same-client consistency between file-creation and a subsequent "list" request. Same-client deletes will remove associated entries from the cache, so that same-client create-followed-by-delete will not erroneously supplement a nonexistent object. List-after-delete consistency is implemented by blacklisting associated entries. Cache staleness in the face of cross-client operations is mitigated by the fact that the cached GoogleCloudStorageItemInfo can be configured to expire with a shorter lifespan than the cache entry itself; when the GoogleCloudStorageItemInfo is fetched lazily, 404s allow pre-emptively removing stale deleted CacheEntries, and likewise, non-404s allow removing an incorrect cache-blacklist entry.
The tradeoff of using this cache is that cross-client deletes may take longer to become visible, if the associated GoogleCloudStorageItemInfo is still active in the cache after another client deletes the associated object. To summarize:
1. Same-client 'create' followed by 'list' will be immediately consistent. 2. Cross-client 'delete' followed by 'list' will be worse than pure-GCS. 3. Same-client 'delete' followed by 'list' is unchanged with respect to eventual consistency.
This class is thread-safe.
DirectoryListCache.Config, DirectoryListCache.TypecacheConfig, clock| Constructor and Description |
|---|
InMemoryDirectoryListCache()
Callers should usually only obtain an instance via
getInstance() so that cache
info is shared process-wide, but instances can be created for temporary caches. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsEntriesForImplicitDirectories()
We don't inspect StorageResourceIds in putResourceId to auto-insert entries for parent
directories, nor do we return fake entries in getObjectList when a delimiter implies a
pure-prefix match.
|
List<CacheEntry> |
getBucketList() |
CacheEntry |
getCacheEntry(StorageResourceId resourceId)
Returns the CacheEntry associated with
resourceId, or null if it doesn't exist. |
static DirectoryListCache |
getInstance()
Accessor for shared singleton instance of DirectoryListCache.
|
int |
getInternalNumBuckets()
Gets the internal number of CachedBucket entries, which may not be equal to the size of
getBucketList() if there are expired entries.
|
int |
getInternalNumObjects()
Gets the internal total count of cached StorageObject entries.
|
List<CacheEntry> |
getObjectList(String bucketName,
String objectNamePrefix,
String delimiter,
Set<String> returnedPrefixes) |
List<CacheEntry> |
getRawBucketList() |
CacheEntry |
putResourceId(StorageResourceId resourceId)
Adds the names of the Bucket or StorageObject referenced by
resourceId to the cache,
with no attached metadata. |
void |
removeResourceId(StorageResourceId resourceId)
Removes CacheEntry associated with
resourceId, if it exists. |
boolean |
supportsCacheEntryByReference()
We use in-memory data structures to hold CacheEntry items, and thus manage them in a shared
manner; returned CacheEntry items are shared references, and updating their cached info
effectively updates the entry's info for all users of the cache.
|
getMutableConfig, isCacheEntryExpired, maybeInvalidateExpiredInfo, setClock, validateResourceIdpublic InMemoryDirectoryListCache()
getInstance() so that cache
info is shared process-wide, but instances can be created for temporary caches.public static DirectoryListCache getInstance()
public boolean supportsCacheEntryByReference()
supportsCacheEntryByReference in class DirectoryListCachepublic boolean containsEntriesForImplicitDirectories()
containsEntriesForImplicitDirectories in class DirectoryListCachepublic CacheEntry putResourceId(StorageResourceId resourceId)
DirectoryListCacheresourceId to the cache,
with no attached metadata. If the entry already exists, then nothing is modified. If resourceId
is a StorageObject, the parent Bucket name is also added to the cache, if it doesn't already
exist.
TODO(user): Even if the entry exists, it might be correct to invalidate any existing metadata
and force a refresh next time it is fetched.putResourceId in class DirectoryListCachepublic CacheEntry getCacheEntry(StorageResourceId resourceId)
DirectoryListCacheresourceId, or null if it doesn't exist.
This returns the real mutable CacheEntry (rather than a copy of the data) so that the
caller may efficiently update the info stored in the CacheEntry if necessary.getCacheEntry in class DirectoryListCachepublic void removeResourceId(StorageResourceId resourceId)
DirectoryListCacheresourceId, if it exists. Cached
GoogleCloudStorageItemInfo associated with the resourceId is also removed, if it exists.
If resourceId denotes a non-empty bucket, then all the cached StorageObject children
of that bucket will also be removed from the cache; it is the caller's responsibility to
ensure that the bucket should really be removed. Note that normal expiration of a CachedBucket
will *not* remove the actual CachedBucket, even though the bucketName will stop appearing
in calls to getBucketList().removeResourceId in class DirectoryListCachepublic List<CacheEntry> getBucketList()
getBucketList in class DirectoryListCachepublic List<CacheEntry> getRawBucketList()
getRawBucketList in class DirectoryListCachepublic List<CacheEntry> getObjectList(String bucketName, String objectNamePrefix, String delimiter, Set<String> returnedPrefixes)
getObjectList in class DirectoryListCachebucketName - The bucket inside of which to list objects.objectNamePrefix - The prefix to be used to match object names to return.delimiter - The character for specifying 'directory' boundaries, or null.returnedPrefixes - A container to be populated with implied "directory objects" that
come from some object which includes the prefix, followed by some string, then followed
by the 'delimiter'. This may or may not be a duplicate of one of the actual returned
directory objects. For example, if gs://foo/bar/baz.txt exists and we query with parameters
("foo", "ba", "/", {}) then the returnedPrefixes will be populated with the string
"bar/" by virtue of existence of the "bar/baz.txt" file. May be null if the caller doesn't
desire fetching such returnedPrefixes.bucketName which
match the provided objectNamePrefix and delimiter, or possibly null if no such objects
are present. May also return an empty list.public int getInternalNumBuckets()
DirectoryListCachegetInternalNumBuckets in class DirectoryListCachepublic int getInternalNumObjects()
DirectoryListCachegetInternalNumObjects in class DirectoryListCacheCopyright © 2015. All rights reserved.