Prev Demo
AngularJS
>
Remove From Cache
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script> </head> <body> <b>Instruction :</b> <p> 1. Add few items into cache. </p> <p> 2. To Read, Update, Remove keep the existing keys into key text box and click on respective buttons to get the result. </p> <p> 3. Click "Remove All" button to remove all items at once. </p> <p> 4. Click "Dispose Cache Object" button to destroy the cache object that remove all items from the cache also. </p> <hr /> <script> var app = angular.module("app", []); app.controller("CacheController", ['$scope', '$cacheFactory', function ($scope, $cacheFactory) { $scope.cacheKeys = []; $scope.cacheData = ''; $scope.cacheObject = $cacheFactory("newCacheInstance"); $scope.add = function (key, value) { $scope.cacheObject.put(key, value); $scope.cacheKeys.push(key); }; $scope.update = function (key, value) { $scope.cacheObject.put(key, value); }; $scope.read = function (key) { $scope.cacheData = $scope.cacheObject.get(key); }; $scope.remove = function (key) { $scope.cacheObject.remove(key); }; $scope.removeAll = function (key) { $scope.cacheObject.removeAll(); }; $scope.Dispose = function (key) { $scope.cacheObject.destroy(); }; }]); </script> <div ng-app="app" ng-controller="CacheController"> Cache key: <input type="text" ng-model="cacheKey" placeholder="cacheKey"/> Cache value: <input type="text" ng-model="cacheValue" placeholder="cacheValue" /> <div><br /> <button ng-click="add(cacheKey, cacheValue)">Add</button> <button ng-click="read(cacheKey)">Read</button> <button ng-click="update(cacheKey, cacheValue)">Update</button> <button ng-click="remove(cacheKey)">Remove</button> <button ng-click="removeAll()">Remove All</button> <button ng-click="Dispose()">Dispose Cache Object</button> </div> <hr /> <ol> <li ng-repeat="key in cacheKeys"> <span ng-bind="key"></span> : <span ng-bind="cacheObject.get(key)"></span> </li> </ol> Cache data: <span ng-bind="cacheData"></span> <hr /> <b>Cache info</b> <ul> <li ng-repeat="(key, value) in cacheObject.info()"> <span ng-bind="key"></span> : <span ng-bind="value"></span> </li> </ul> </div> </body> </html>
Note: We DO NOT save your trial code in our database.
Output