Question

I have a method that we call to get the reference to the CloudTable before I write or query table storage.

private static CloudTable GetCloudTable() {
   var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
   var tableClient = storageAccount.CreateCloudTableClient();
   var table = tableClient.GetTableReference("TheTableName");
   return table;
}

Is acceptable to put this in the constructor of my table handling class? Is it an additional overhead to run this code on every table insert? It seems to me that I am increasing the number of transactions that I am running.

Was it helpful?

Solution

Your code snippets does not make any message to be sent to the Storage Service. The actual message is sent only when you use the "table" variable to actually Create, Query, or perform any CRUD operation against the storage. So the answer to "am I increasing the number of transactions by running this code on every table insert?" is NO.

That said, CloudStorageAccount.Parse and CloudConfigurationManager.GetSetting (the first line in your code snippet) do create some overhead (string parsing and configuration item retrieving). So for sure I suggest you to perform them only once and then reuse their result in every table operation(yes, putting this in the constructor IS an option).

However, the CloudTableClient object returned by CreateCloudTableClient() is not guaranteed to be thread safe. So IF threading is a issue in your evnvironment (i.e. you are you are using the same instance of your class from multple threads), I suggest to create a new instance of CloudTableClient every time you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top