Friday, May 4, 2018

Configure azure disk caching


The disk that are attached to a VM has a option to set cache preference to manage local cache that are used for read or write operations. This settings can used to improve performance.

There are three cache options:

  • None 
  • Read Only 
  • Read/Write

Following are the steps to set the caching preference using portal

Navigate to the azure portal and click Virtual Machines




x
Azure Virtual Machines

Select the VM and click Disk from the blade

Azure host caching

Click Edit from the menu and select the appropriate Host Caching from the drop down.

Azure host caching

Click Save to save the changes.

Following are the steps to set the preferences using powershell

Azure Disk Caching in PowerShell

Powershell commands to update the host caching preferences.

Following example sets the caching to None
$vm  = Get-AzureRmVM -ResourceGroupName cprg -VMName cpvm
$vm.storageprofile.osdisk.Caching="None"

Other options
$vm.storageprofile.osdisk.Caching="ReadWrite"
$vm.storageprofile.osdisk.Caching="ReadOnly"


Thursday, April 26, 2018

Filter object using ES6

Scenario:

Assume we have the following object

ingredients = { 'pizza': false, 'basil': true, 'olives': false }

Requirement:

Filter object based on its values using ES6/JS. We need to get the filter the above object which has value set to true.

Solution:

The object can be filtered using filter and map functions.

let filteredIngredients = Object.keys(ingredients)
              .filter((value) => {
                  return ingredients[value] == true;
}).map((ingredient, index) => {
    return ingredient;
              });

console.log(filteredIngredients);

Output:

["pizza", "basil"]