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
sql.request() | |
.input('Nome', 'Gustavo') | |
.input('NomeDaMae', 'Joana') | |
.execute('BuscarUsuario', (err, recordset) => { | |
if(err) | |
return console.log(err); | |
console.log(recordset); | |
}); |
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
let transaction = sql.transaction(); | |
transaction.begin((err) = > { | |
if(err) | |
return console.log(err); | |
sql.request(transaction) | |
.input('Nome', 'Gustavo') | |
.input('NomeDaMae', 'Joana') | |
.execute('BuscarUsuario', (err, recordset) => { |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMemoryCache(); | |
services.AddMvc(); | |
} |
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
public class HomeController : Controller | |
{ | |
private IMemoryCache _cache; | |
public HomeController(IMemoryCache memoryCache) | |
{ | |
_cache = memoryCache; | |
} | |
//resto do Controller... |
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
public IActionResult Index() | |
{ | |
//Verifica se existe ou não valor em um cache chamado "DataAtual" | |
if (!_cache.TryGetValue("DataAtual", out DateTime dataAtual)) | |
{ | |
//Caso não exista, colocamos a data atual | |
dataAtual = DateTime.Now; | |
//Aqui configuramos as opções do cache | |
var cacheEntryOptions = new MemoryCacheEntryOptions() |
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
@{ | |
ViewData["Title"] = "Home Page"; | |
} | |
<div class="row"> | |
<div class="col-md-12"> | |
<h2>Data atual</h2> | |
<p><b>@ViewBag.DataAtual</b></p> | |
</div> | |
</div> |
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
public IActionResult GetOrCreateCache() | |
{ | |
var dataAtual = _cache.GetOrCreate("DataAtual", dataCache => | |
{ | |
dataCache.SetSlidingExpiration(TimeSpan.FromSeconds(10)); | |
dataCache.SetPriority(CacheItemPriority.NeverRemove); | |
return DateTime.Now; | |
}); | |
ViewBag.DataAtual = dataAtual; |
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
@{ | |
ViewData["Title"] = "Home Page"; | |
} | |
<div class="row"> | |
<div class="col-md-12"> | |
<h2>Data atual</h2> | |
<p>Data do cache: <b>@ViewBag.DataAtual</b></p> | |
<p>Data atual: <b>@DateTime.Now</b></p> | |
</div> |
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
_cache.Remove("DataAtual"); |
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
if(algumaCondicao) | |
return valorCasoSejaVerdadeira; | |
else | |
return valorCasoSejaFalsa; |