var request = require("request");
// создаем класс для кэширования результатов запросов
var СacheRequest = function() {
// конструктор
// создаем ассоциативный массив для кэширования результата
this.cache = {};
};
// основной метод класса, предназначен для получения данных по ссылке
// принимает url в качестве параметра
// возвращает выполненный промис если запрос есть в кэше
// или промис в ожидании выполнения запроса
СacheRequest.prototype.get = function(url) {
var self = this;
// если такой запрос уже был, возвращаем промис с результатом из кэша
if( this.cache[url] )
return Promise.resolve(this.cache[url]);
// иначе возвращаем промис с ожиданием результата
return new Promise(function(resolve,reject){
// делаем запрос на указанный url
request(url, function(error, response, body){
// если ошибка - реджектим )
if( error )
return reject(error);
// иначе запоминаем в кэше ответ
self.cache[url] = body;
// и резолвим body
resolve(body);
});
});
};
// метод отчищает кэш
СacheRequest.prototype.clear= function(){
this.cache = {};
};
// создаем экземпляр кэша
var cacheRequest = new СacheRequest();
// так как request асинхронный, то для того, чтобы получить
// результат запроса используем метод .then у возвращаемого промиса
// выполняем запросы:
// запросим "http://google.ru/" (будет сделан фактический запрос)
cacheRequest.get("http://google.ru/")
.then(function(body1){
console.log("\n\n\nBODY:", body1, 111);
//теперь еще раз запросим "http://google.ru/" (будет взято из кэша)
cacheRequest.get("http://google.ru/")
.then(function(body2){
console.log("\n\n\nBODY:", body2, 222);
});
});
// раз в сутки отчищаем кэш
setTimeout( function(){
cacheRequest.clear();
}, 1000*60*60*24 ); // 1000*60*60*24 это количество миллисекунд в сутках
вопрос был о технической части работы абстрактного пикселя ретаргетинга.
Подскажите, пожалуйста, как работают пиксели ретаргетинга (ОК, ВК, ФБ)?
genSaltSync(rounds, minor)
rounds - [OPTIONAL] - the cost of processing the data. (default - 10)
minor - [OPTIONAL] - minor version of bcrypt to use. (default - b)
genSalt(rounds, minor, cb)
rounds - [OPTIONAL] - the cost of processing the data. (default - 10)
minor - [OPTIONAL] - minor version of bcrypt to use. (default - b)
cb - [OPTIONAL] - a callback to be fired once the salt has been generated. uses eio making it asynchronous. If cb is not specified, a Promise is returned if Promise support is available.
err - First parameter to the callback detailing any errors.
salt - Second parameter to the callback providing the generated salt.
hashSync(data, salt)
data - [REQUIRED] - the data to be encrypted.
salt - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under Usage).
hash(data, salt, cb)
data - [REQUIRED] - the data to be encrypted.
salt - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under Usage).
cb - [OPTIONAL] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous. If cb is not specified, a Promise is returned if Promise support is available.
err - First parameter to the callback detailing any errors.
encrypted - Second parameter to the callback providing the encrypted form.
compareSync(data, encrypted)
data - [REQUIRED] - data to compare.
encrypted - [REQUIRED] - data to be compared to.
compare(data, encrypted, cb)
data - [REQUIRED] - data to compare.
encrypted - [REQUIRED] - data to be compared to.
cb - [OPTIONAL] - a callback to be fired once the data has been compared. uses eio making it asynchronous. If cb is not specified, a Promise is returned if Promise support is available.
err - First parameter to the callback detailing any errors.
same - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
getRounds(encrypted) - return the number of rounds used to encrypt a given hash
encrypted - [REQUIRED] - hash from which the number of rounds used should be extracted.