-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from MaxCDN/feature/better_delete
Better (faster) delete w/ files.
- Loading branch information
Showing
5 changed files
with
165 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var MaxCDN = require('../index'); | ||
var maxcdn = new MaxCDN(process.env.ALIAS, process.env.KEY, process.env.SECRET); | ||
var async = require('async'); | ||
var format = require('util').format; | ||
|
||
var post_name = Date.now().toString() + 'timer'; | ||
var timers = []; | ||
var zoneid; | ||
|
||
// fetch zoneid for timers | ||
maxcdn.get('/zones/pull.json', function (err, res) { | ||
zoneid = res.data.pullzones[0].id; | ||
|
||
// timers | ||
timer('GET /reports/popularfiles.json', function (callback) { | ||
maxcdn.get('/reports/popularfiles.json', function (err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
timer('PUT /reports/account.json/address', function (callback) { | ||
maxcdn.put('account.json/address', "street2="+post_name, function(err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
timer('POST /zones/pull.json', function (callback) { | ||
var zone = { | ||
name: post_name, | ||
url: 'http://www.example.com' | ||
}; | ||
|
||
maxcdn.post('/zones/pull.json', zone, function (err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
timer('DELETE /zones/pull.json/PULL_ZONE', function (callback) { | ||
maxcdn.delete('/zones/pull.json/'+post_name, function (err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
timer('DELETE /zones/pull.json/'+zoneid+'/cache', function (callback) { | ||
maxcdn.delete('/zones/pull.json/'+zoneid+'/cache', function (err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
timer('DELETE /zones/pull.json/'+zoneid+'/cache w/ [ files ]', function (callback) { | ||
maxcdn.delete('/zones/pull.json/'+zoneid+'/cache', | ||
[ '/master.css', '/favicon.ico' ], | ||
function (err, res) { | ||
callback(err); | ||
}); | ||
}); | ||
|
||
// run timers | ||
async.series(timers); | ||
}); | ||
|
||
// timer function | ||
function timer(label, test) { | ||
timers.push(function (callback) { | ||
var start = new Date(); | ||
process.stdout.write(label+': '); | ||
test( function (err) { | ||
if (err) { | ||
console.log('FAILED'); | ||
console.trace(err); | ||
return; | ||
} | ||
console.log('%s ms', new Date() - start); | ||
callback(); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters