0% acharam este documento útil (0 voto)
2 visualizações3 páginas

Com 0

O documento discute a implementação de um sistema de cache em memória e armazenamento local para otimizar o acesso a dados. Ele descreve métodos para validar, adicionar e recuperar dados do cache, além de gerenciar erros e diagnósticos durante o processo. O foco está na eficiência e na manutenção da integridade dos dados durante as operações de rede.

Enviado por

rak kiesz
Direitos autorais
© All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato DOCX, PDF, TXT ou leia on-line no Scribd
0% acharam este documento útil (0 voto)
2 visualizações3 páginas

Com 0

O documento discute a implementação de um sistema de cache em memória e armazenamento local para otimizar o acesso a dados. Ele descreve métodos para validar, adicionar e recuperar dados do cache, além de gerenciar erros e diagnósticos durante o processo. O foco está na eficiência e na manutenção da integridade dos dados durante as operações de rede.

Enviado por

rak kiesz
Direitos autorais
© All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato DOCX, PDF, TXT ou leia on-line no Scribd

ser)

(e,this._options),n=this._getCacheKey(t),i=this._inMemoryCache.get(n,t);if(i&&th
is._getIsCacheValueValid(i))return i;const r=this._loadFromCache(n);return
r&&this._getIsCacheValueValid(r)?
(this._inMemoryCache.add(n,r,this._cacheLimit),this._inMemoryCache.get(n,t)):nul
l}setData(e,t){const n=t&&(0,o._normalizeUser)
(t,this._options),i=this._getCacheKey(n);this._inMemoryCache.add(i,u("Bootstrap"
,e,null,n),this._cacheLimit)}_getIsCacheValueValid(e){return null==[Link]||
[Link]===[Link](this._getSdkKey())}_getDataAsyncImpl(e,t,n){return
i(this,void 0,void 0,(function*(){[Link]()||(yield
[Link]());const i=null!=e?
e:[Link](t),s=[this._fetchAndPrepFromNetwork(i,t,n)];return(null==n?
void 0:[Link])&&[Link](new
Promise((e=>setTimeout(e,[Link]))).then((()=>([Link]("Fetching latest
value timed out"),null)))),yield [Link](s)}))}_prefetchDataImpl(e,t)
{return i(this,void 0,void 0,(function*(){const n=e&&(0,o._normalizeUser)
(e,this._options),i=this._getCacheKey(n),r=yield
this._getDataAsyncImpl(null,n,t);r&&this._inMemoryCache.add(i,[Link](Obje
[Link]({},r),
{source:"Prefetch"}),this._cacheLimit)}))}_fetchAndPrepFromNetwork(e,t,n){return
i(this,void 0,void 0,(function*(){var i;const o=null!==(i=null==e?void
0:[Link])&&void 0!==i?i:null,a=null!
=e&&this._isCachedResultValidFor204(e,t),c=yield
this._fetchFromNetwork(o,t,n,a);if(!c)return [Link]("No response returned
for latest value"),null;const d=(0,l._typedJsonParse)
(c,"has_updates","Response"),g=this._getSdkKey(),_=[Link](g);let
h=null;if(!0===(null==d?void 0:d.has_updates))h=u("Network",c,_,t);else{if(!o||!
1!==(null==d?void 0:d.has_updates))return
null;h=u("NetworkNotModified",o,_,t)}const f=this._getCacheKey(t);return
this._inMemoryCache.add(f,h,this._cacheLimit),this._writeToCache(f,h),h}))}_getS
dkKey(){return null!=this._sdkKey?this._sdkKey:([Link](`$
{this._adapterName} is not attached to a Client`),"")}_loadFromCache(e){var
t;const n=null===(t=[Link])||void 0===t?void
0:[Link]([Link],e);if(null==n)return null;const i=(0,l._typedJsonParse)
(n,"source","Cached Result");return i?[Link]([Link]({},i),
{source:"Cache"}):null}_writeToCache(e,t){const n=[Link](t);for(let
t=0;t<8;t++)try{[Link](e,n);break}catch(t){if(!(t instanceof
Error)||"QuotaExceededError"!==[Link]||this._cacheLimit<=1)throw
t;this._cacheLimit=[Link](this._cacheLimit/2),this._runLocalStorageCacheEvict
ion(e,this._cacheLimit-
1)}this._runLocalStorageCacheEviction(e)}_runLocalStorageCacheEviction(e,t=this.
_cacheLimit){var n;const i=null!==(n=(0,a._getObjectFromStorage)
(this._lastModifiedStoreKey))&&void 0!==n?n:{};i[e]=[Link]();const
r=d(i,t);for(const e of r)delete i[e],[Link](e);
(0,a._setObjectInStorage)
(this._lastModifiedStoreKey,i)}},t._makeDataAdapterResult=u;class
c{constructor(){this._data={}}get(e,t){var n;const i=this._data[e],s=null==i?
void 0:[Link],o=null===(n=null==t?void 0:[Link])||void 0===n?void
0:[Link];return o&&s&&o!==s?([Link]("'[Link]'
mismatch"),null):i}add(e,t,n){const i=d(this._data,n-1);for(const e of i)delete
this._data[e];this._data[e]=t}merge(e)
{this._data=[Link]([Link]({},this._data),e)}}function d(e,t){const
n=[Link](e);return [Link]<=t?[]:0===t?n:[Link](((t,n)=>{const
i=e[t],r=e[n];return"object"==typeof i&&"object"==typeof r?[Link]-
[Link]:i-r})).slice(0,[Link]-t)}},882:(e,t)=>{"use
strict";[Link](t,"__esModule",{value:!0}),[Link]=void
0;const n=new Map,i="start",r="end";function s(e,t,n,i){return
[Link]({key:n,action:t,step:i,timestamp:[Link]()},e)}function o(e,t)
{var i;const r=null!==(i=[Link](e))&&void 0!==i?i:
[];[Link](t),[Link](e,r)}function a(e,t){if(t in e)return
e[t]}[Link]={_getMarkers:e=>[Link](e),_markInitOverallStart:e=>{o(e,s({},i
,"overall"))},_markInitOverallEnd:(e,t,n)=>{o(e,s({success:t,error:t?void 0:
{name:"InitializeError",message:"Failed to
initialize"},evaluationDetails:n},r,"overall"))},_markInitNetworkReqStart:
(e,t)=>{o(e,s(t,i,"initialize","network_request"))},_markInitNetworkReqEnd:
(e,t)=>{o(e,s(t,r,"initialize","network_request"))},_markInitProcessStart:e=>{o(
e,s({},i,"initialize","process"))},_markInitProcessEnd:
(e,t)=>{o(e,s(t,r,"initialize","process"))},_clearMarkers:e=>{[Link](e)},_form
atError(e){if(e&&"object"==typeof
e)return{code:a(e,"code"),name:a(e,"name"),message:a(e,"message")}},_getDiagnost
icsData(e,n,i,r){var s;return{success:!0===(null==e?void
0:[Link]),statusCode:null==e?void 0:[Link],sdkRegion:null===(s=null==e?void
0:[Link])||void 0===s?void 0:[Link]("x-statsig-region"),isDelta:!
0===[Link]('"is_delta":true')||void
0,attempt:n,error:[Link]._formatError(r)}},_enqueueDiagnosticsEvent(e,n,i
,r){const s=[Link]._getMarkers(i);if(null==s||[Link]<=0)return-1;const
o=s[[Link]-1].timestamp-s[0].timestamp;[Link]._clearMarkers(i);const
a=function(e,t)
{return{eventName:"statsig::diagnostics",user:e,value:null,metadata:t,time:Date.
now()}}(e,{context:"initialize",markers:[Link](),statsigOptions:r});return
[Link](a),o}}},457:function(e,t){"use strict";var n=this&&this.__awaiter||
function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e)
{try{l([Link](e))}catch(e){s(e)}}function a(e){try{l([Link](e))}catch(e)
{s(e)}}function l(e){var t;[Link]?r([Link]):(t=[Link],t instanceof n?t:new
n((function(e){e(t)}))).then(o,a)}l((i=[Link](e,t||
[])).next())}))};[Link](t,"__esModule",{value:!
0}),t._fetchTxtRecords=void 0;const i=new
Uint8Array([0,0,1,0,0,1,0,0,0,0,0,0,13,102,101,97,116,117,114,101,97,115,115,101
,116,115,3,111,114,103,0,0,16,0,1]),r=["i","e","d"];t._fetchTxtRecords=function(
e){return n(this,void 0,void 0,(function*(){const t=yield e("[Link]
[Link]/dns-query",{method:"POST",headers:{"Content-Type":"application/dns-
message",Accept:"application/dns-message"},body:i});if(![Link]){const e=new
Error("Failed to fetch TXT records from DNS");throw
[Link]="DnsTxtFetchError",e}const n=yield [Link]();return function(e)
{const
t=[Link](((t,n)=>n<200&&"="===[Link](t)&&[Link]([Link]
mCharCode(e[n-1]))));if(-1===t){const e=new Error("Failed to parse TXT records
from DNS");throw [Link]="DnsTxtParseError",e}let n="";for(let i=t-
1;i<[Link];i++)n+=[Link](e[i]);return [Link](",")}(new
Uint8Array(n))}))}},4387:(e,t)=>{"use
strict";[Link](t,"__esModule",{value:!0})},4358:function(e,t,n)
{"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||
(n=Promise))((function(r,s){function o(e){try{l([Link](e))}catch(e)
{s(e)}}function a(e){try{l([Link](e))}catch(e){s(e)}}function l(e){var
t;[Link]?r([Link]):(t=[Link],t instanceof n?t:new n((function(e)
{e(t)}))).then(o,a)}l((i=[Link](e,t||
[])).next())}))};[Link](t,"__esModule",{value:!
0}),[Link]=t.EXCEPTION_ENDPOINT=void 0;const
r=n(8024),s=n(686),o=n(6512);t.EXCEPTION_ENDPOINT="[Link]
sdk_exception";const a="[Statsig] UnknownError";function l(e){return e
instanceof Error?e:"string"==typeof e?new Error(e):new Error("An unknown error
occurred.")}function u(e){if(!e)return{};const t={};return
[Link](e).forEach((n=>{const i=n,r=e[i];switch(typeof r)
{case"number":case"bigint":case"boolean":t[String(i)]=r;break;case"string":[Link]
gth<50?t[String(i)]=r:t[String(i)]="set";break;case"object":"environment"===i?
[Link]=r:"networkConfig"===i?[Link]=r:t[String(i)]=null!
=r?"set":"unset"}})),t}[Link]=class{constructor(e,t,n,i)
{this._sdkKey=e,this._options=t,this._emitter=n,this._lastSeenError=i,this._seen
=new Set}wrap(e,t){try{const n=e;(function(e){const t=new Set;let
n=[Link](e);for(;n&&n!
==[Link];)[Link](n).filter((e=>"function"==typeof(
null==n?void 0:n[e]))).forEach((e=>[Link](e))),n=[Link](n);return
[Link](t)})(n).forEach((i=>{const r=n[i];"$EB"in r||
(n[i]=(...n)=>this._capture(t?`${t}:${i}`:i,(()=>[Link](e,n))),n[i].$EB=!
0)}))}catch(e){this._onError("eb:wrap",e)}}logError(e,t)
{this._onError(e,t)}getLastSeenErrorAndReset(){const
e=this._lastSeenError;return this._lastSeenError=void 0,null!=e?
e:null}attachErrorIfNoneExists(e){this._lastSeenError||
(this._lastSeenError=l(e))}_capture(e,t){try{const n=t();return n&&n instanceof
Promise?[Link]((t=>this._onError(e,t))):n}catch(t){return
this._onError(e,t),null}}_onError(e,n){try{[Link](`Caught error in ${e}`,
{error:n}),(()=>i(this,void 0,void 0,(function*(){var i,r,c,d,g,_,h;const f=n||
Error(a),v=f instanceof Error,p=v?[Link]:"No
Name",m=l(f);if(this._lastSeenError=m,this._seen.has(p))return;if(this._seen.add
(p),null===(r=null===(i=this._options)||void 0===i?void 0:[Link])||void
0===r?void 0:[Link])return void(null===(c=this._emitter)||
void 0===c||[Link](this,{name:"error",error:n,tag:e}));const
y=[Link]._get(this._sdkKey),b=[Link](),S=v?
[Link]:function(e){try{return [Link](e)}catch(e){return a}}
(f),E=[Link]({tag:e,exception:p,info:S,statsigOptions:u(this._options)},O
[Link]([Link]({},b),{sdkType:y})),w=null!
==(_=null===(g=null===(d=this._options)||void 0===d?void 0:[Link])||
void 0===g?void 0:[Link])&&void 0!==_?_:fetch;yield
w(t.EXCEPTION_ENDPOINT,{method:"POST",headers:{"STATSIG-API-
KEY":this._sdkKey,"STATSIG-SDK-TYPE":String(y),"STATSIG-SDK-
VERSION":String([Link]),"Content-Type":"application/
json"},body:[Link](E)}),null===(h=this._emitter)||void 0===h||
[Link](this,{name:"error",error:n,tag:e})})))().then((()=>{})).catch((()

Você também pode gostar