public class FileSystemBackedDirectoryListCache extends DirectoryListCache
This class does *not* support caching the GoogleCloudStorageItemInfo alongside filenames; it is strictly for supplementing listed filenames, and any returned CacheEntry should not be expected to contain a GoogleCloudStorageItemInfo regardless of info-expiration settings.
This class is thread-safe.
DirectoryListCache.Config, DirectoryListCache.TypecacheConfig, clock| Constructor and Description |
|---|
FileSystemBackedDirectoryListCache(String basePathStr) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsEntriesForImplicitDirectories()
Since our backing store has no notion of "implicit" directories, automatically cache directory
objects for 'implicit' directories, by virtue of having to create those real directories
to insert the child object at all.
|
List<CacheEntry> |
getBucketList() |
CacheEntry |
getCacheEntry(StorageResourceId resourceId)
Returns the CacheEntry associated with
resourceId, or null if it doesn't exist. |
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() |
static FileSystemBackedDirectoryListCache |
getUninitializedInstanceForTest()
Returns an instance not bound to a basePath for testing purposes.
|
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. |
void |
setBasePath(String basePathStr)
Only exposed for testing purposes; shouldn't be called outside of tests.
|
boolean |
supportsCacheEntryByReference()
We use a real filesystem as our authoritative cache, and thus CacheEntries are not shared
references.
|
getMutableConfig, isCacheEntryExpired, maybeInvalidateExpiredInfo, setClock, validateResourceIdpublic FileSystemBackedDirectoryListCache(String basePathStr)
basePathStr - The absolute path under which to place all mirrored directory trees;
Paths.get(basePathStr).isAbsolute() must return true.public static FileSystemBackedDirectoryListCache getUninitializedInstanceForTest()
public boolean supportsCacheEntryByReference()
supportsCacheEntryByReference in class DirectoryListCachepublic boolean containsEntriesForImplicitDirectories()
containsEntriesForImplicitDirectories in class DirectoryListCachepublic CacheEntry putResourceId(StorageResourceId resourceId) throws IOException
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 DirectoryListCacheIOExceptionpublic CacheEntry getCacheEntry(StorageResourceId resourceId) throws IOException
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 DirectoryListCacheIOExceptionpublic void removeResourceId(StorageResourceId resourceId) throws IOException
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 DirectoryListCacheIOExceptionpublic List<CacheEntry> getBucketList() throws IOException
getBucketList in class DirectoryListCacheIOExceptionpublic List<CacheEntry> getRawBucketList() throws IOException
getRawBucketList in class DirectoryListCacheIOExceptionpublic List<CacheEntry> getObjectList(String bucketName, String objectNamePrefix, String delimiter, Set<String> returnedPrefixes) throws IOException
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.IOExceptionpublic int getInternalNumBuckets()
throws IOException
DirectoryListCachegetInternalNumBuckets in class DirectoryListCacheIOExceptionpublic int getInternalNumObjects()
throws IOException
DirectoryListCachegetInternalNumObjects in class DirectoryListCacheIOExceptionpublic void setBasePath(String basePathStr)
Copyright © 2015. All rights reserved.