A5Storage::NameCache Class
Syntax
A5Storage::NameCache()
A5Storage::NameCache(Storages as C)
Arguments
- StoragesCharacter
A CR-LF delimited list of storages. See examples below.
Description
A container for named connection strings.
Discussion
The caller is responsible for managing the contents and for providing the cache to use when calling A5Storage::DataContainer::Open() or A5Storage::SubContainer::Open().
Creating an A5Storage::NameCache Object
A NameCache object can be created using the A5Storage::NameCache constructor. Storages can be specified in the constructor or added later using the AddItems method. For example:
dim Storages as C = <<%txt% Storage1 Provider='Disk';Container='C:\A5WebRoot1'; Storage2 Provider='Disk';Container='C:\A5WebRoot2'; %txt% dim Cache as A5Storage::NameCache if Cache.AddItems(Storages) ' do stuff here else ' Oops! showvar("Oops!" + crlf() + Cache.CallResult.Text) end if
This example demonstrates adding storages when the A5Storage::NameCache item is created using the constructor:
dim Storages as C = <<%txt% Storage1 Provider='Disk';Container='C:\A5WebRoot1'; Storage2 Provider='Disk';Container='C:\A5WebRoot2'; %txt% dim Cache as A5Storage::NameCache = new A5Storage::NameCache(Storages)
Using A5Storage::NameCache with Containers
The example script below shows how you can create and use a cache of names with A5Storage::Container to automatically translate named connections.
dim Storages as C = <<%txt% Store1 Provider='Disk';Container='C:\A5WebRoot1'; Store2 Provider='Disk';Container='C:\A5WebRoot2'; Invalid Provider='Disk';Container='AA:\abc'; %txt% dim TestStorages as C = <<%txt% Store1 Store2 Invalid NotFound %txt% Result = RunTest(Storages, TestStorages) showvar(Result) FUNCTION RunTest as C (Storages as C, TestStorages as C) dim Result as C dim cache as a5storage::NameCache = new a5storage::NameCache(Storages) for i = 1 to w_count(TestStorages, crlf()) CurrentItem = word(TestStorages, i, crlf()) CurrentName = word(CurrentItem, 1, chr(9)) Result = Result + "Testing Name: " + CurrentName + crlf() + TestName(Cache, "::name::" + CurrentName) next RunTest = Result END FUNCTION FUNCTION TestName(Cache as A5Storage::NameCache, Name as C) dim Result as C dim sc as a5storage::DataContainer = null_value() CallResult = A5Storage::DataContainer::Open(sc, Cache, Name) if CallResult.Success dim ItemName as C = "test/Data.Txt" dim ItemValue as C = "StorageData" dim ItemContentType as C = "text" if sc.SetItem(ItemValue, ItemContentType, ItemName) dim di as A5Storage::DataItem = null_value() if sc.ReferenceItem(di, ItemName) dim Text AS C dim ContentType as C di.Get(Text, ContentType) Result = "Item: " + ItemName + " = " + Text + crlf() Result = Result + chr(9) + chr(9) + "Modified: " + di.ModifiedTime + crlf() Result = Result + chr(9) + chr(9) + "ContentType: " + di.ContentType + crlf() Result = Result + chr(9) + chr(9) + "Size: " + di.Size + crlf(2) else Result = "Error referencing item '" + ItemName + "':" + sc.CallResult.Text end if else Result = "Error setting item: " + sc.CallResult.Text + crlf() end if else Result = "Error opening container '" + Name + ": " + CallResult.Text + crlf() end if TestName = Result END FUNCTION
Properties
- CallResultCallResult
Contains the status of the last call made on the instance.
- NamedConnectionPrefixCharacter
The prefix used for named connections. E.g. "::NAME::".
- NamesCharacter
Gets or sets the entire cache from or to a string of the format: "name<tab>connectionstring<crlf>"
Each row contains a tab separated name and connection string pair. The rows are delimited with a carriage return and line feed (CR-LF).
Methods
- AddItems Method
Adds storage definitions the NameCache object.
- Clear Method
Clears the cache.
- Find Method
Get the cached connection string for the specified key. If no item exists for the key, connection string will be blank.
- Set Method
Adds or replaces a connection string in the cache.
See Also