Over the years, developers and engineers have made remarkable strides in creating innovative products. However, despite their advancements, the challenge of preventing critical data loss persists. This is where in-memory distributed caching proves invaluable, offering a powerful solution to safeguard data and enhance application performance.
One might think that caching, being a temporary data store, could compromise data reliability. Moreover, in distributed caching, data centers are spread out over several areas and may become victim to natural disasters, resulting in data loss. In these circumstances, there ought to be a means to prevent data loss.
Fortunately, developers facing such data loss can choose from many popular distributed caching options available in the market, like NCache. NCache is an extremely fast and linearly scalable in-memory distributed cache. It enables developers to gear up their businesses and move to a new world of in-memory data-distributed caching as it provides high data availability.
The Necessity of Cache Backup and Restore
Unexpected challenges can arise at any moment in the digital world. Imagine a developer managing an online store that serves thousands of customers daily. Suddenly, the website crashes just as users are finalizing their purchases, and to make matters worse, all the shopping cart data is lost. Without a recent backup to restore from, the developer faces a critical situation. What should the developer do now? Without a rollback option, the developer must quickly assess the damage, communicate transparently with affected customers, and devise a recovery plan to prevent future data loss.
Situations like this make backing up your data critical. To make data highly available under all circumstances and prevent data loss, NCache allows data backups and enables the developer to restore the cached data anytime.
Saving Data with NCache Backup
NCache users can now safeguard their cached data by creating backups. This feature allows users to generate a copy of their data, protecting it from potential disasters, or human errors. NCache will store a backup at a specified file path when data is present in the cache, letting users operate with peace of mind, knowing their data is secure and safe from loss.
Additionally, NCache also allows users to securely restore their cached data back to the cache cluster from its saved location. This feature ensures that users can always recover their backed-up cached data, regardless of the situation.
How to Backup Cache Data to a Specified Path
NCache provides a PowerShell cmdlet, i.e., Export-CacheData, to enable users to back up their data. With this cmdlet, users can save the contents (data) of the cache to any specified path, along with the path for the dependent assemblies.
1 2 |
Export-CacheData [-Name] [-ErrorThreshold] [-FileSize] [-Server] [-Path] [-Credentials] [-NoLogo] |
- Example: The following command backs up all the cached items to a specified path:
1 2 |
Export-CacheData -Name demoCache -Path C:\Backup-path |
- Example:The following command backs up all the keys currently present in the cache with a maximum of 2 MB data files:
1 2 |
Export-CacheData -Name demoCache -Path C:\Backup-path -FileSize 2 |
Some of the important parameters for the cmdlet are explained below:
- Name: Specifies the name of the cache which has been backed up or restored.
- Path: Specifies the path where the backup data is to be created.
- Credentials: Specifies the user credentials required to authorize access for the specified operation. These credentials should belong to a user who has appropriate permissions at the node.
To learn about the other parameters, refer to the documentation.
How to Restore Data to Cache from a Specified Path?
To enable users to restore data to the cache, NCache utilizes the PowerShell cmdlet Import-CacheData. This cmdlet allows users to import cached data from a specified path back into the cache.
The PowerShell cmdlet used for this purpose is:
1 2 |
Import-CacheData [-Name] [-Path] [-BulkSize] [-ErrorThreshhold] [-Expiry] [-NoLogo] [-Credentials] |
- Example: The following command imports the data from the specified file path to the cache:
1 2 |
Import-CacheData -Name demoCache -Path C:\Backup-path |
- Example: The following command recovers the data from the specified path to the cache including the dependent assembly files with a tolerance of a maximum of 10 errors:
1 2 |
Import-CacheData -Name demoCache -Path C:\Backup-path –ErrorThreshhold 10 |
- Example: This command imports the data from the backup source placed on the specified path to the cache including the dependent assembly files. The data items would be restored in bulk of 100 at one time and the display of the logo banner will be suppressed:
1 2 |
Import-CacheData -Name demoCache -Path C:\Backup-path –BulkSize 100 –NoLogo |
Some important cmdlet parameters are explained below:
- Name: Specifies the name of the cache which is to be backed up or restored.
- Path: Specifies the path where the backup data is currently present.
- ErrorThreshold: Specifies the number of errors that can be tolerated during importing files from the backup.
- Expiry: Specifies the expiration policy that gives the time span of the expiry of the data that is restored to the cache.
To learn about the other parameters, refer to the documentation.
Conclusion
NCache is an open-source, in-memory distributed cache designed for long-term storage and data recovery, that protect sensitive data by preventing data loss in the event of a system failure. Therefore, for optimal data safety, utilize the NCache backup and restore feature. Download a fully functional 30-day trial of NCache Enterprise and try it out for yourself.