7.11.77 • Published 12 months ago

@erboladaiorg/totam-ratione-deleniti v7.11.77

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Installation

yarn add @erboladaiorg/totam-ratione-deleniti --save

Usage

const { Cache } = require("@erboladaiorg/totam-ratione-deleniti")

const maxSize = 2 // will limit max cache size upon cache.get()
const getUser = async (id) => {
  const response = await fetch("https://dummyjson.com/users/" + id)
  const { firstName, lastName, address } = await response.json()

  return {
    id,
    name: `${firstName} ${lastName}`,
    address,
  }
}

const usersCached = new Cache(getUser, maxSize)

Promise.all([
  usersCached.get(1),
  usersCached.get(2),
  usersCached.get(3),
  usersCached.get(4),
]).then((users) => {
  console.log(usersCached.data) // contains only last maxSize users (3 and 4)
  console.log(usersCached.size) // 2
})
const { Cache } = require("@erboladaiorg/totam-ratione-deleniti")
// create cache with factory function (may take any number of parameters)
const cache = new Cache(() => Math.random())

// each time you call the cache.get with same parameters
// you will get the same once lazy cached answer
const a = cache.get(1, 2, 3)
const b = cache.get(1, 2, 3) // this will return the same as above
const c = cache.get(1, 2)
const d = cache.get(1, 2, 4)

console.log(a === b) // true
console.log(a !== c) // true
console.log(a !== d) // true

API

class Cache<T = unknown> {
  constructor(factoryFunction: (...args: any[]) => T, maxSize: number = Infinity) {
    //
  }
}
  • creates a LaterMom (Lazy Map) instance with factory function for lazy cache

methods

  • get(...args: any[]): T - get entry at key created from args, lazy instantiated by factory
  • createKey(...args: any[]): string - creates string key
  • create(...args: any[]): T - wrapped factory function
  • hasKey(key: string): boolean - check if has entry at key
  • has(...args: any[]): boolean - check if has entry at key created from args
  • deleteKey(key: string): boolean - deletes entry from data at key
  • delete(...args): boolean - deletes entry from data at key created from args
  • size: number - returns size of data
  • maxSize: number - on insert the oldest items are deleted until reached maxSize

properties:

  • data: Map

Tests

$ jest
 PASS  ./index.test.js
  ✓ Calls factory once when asked for same key many times (62 ms)
  ✓ Getter is able to handle multiple arguments
  ✓ Readme has working code (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.946 s, estimated 1 s
Ran all test suites.
Done in 1.44s.

License

MIT

Author

Jacek Pietal @ 2019-2021

maketypeerrorexitforEachspeedreversedlengthpropertiesinfileendpointchildwhichsnsCSSStyleDeclarationRegExp.prototype.flagspackagesObject.keysserializetypedglobalThismonorepoES8matchesArray.prototype.findLastconfigurableslicereadablestreamjoitoArrayRxchaioptimistwritablegroupBydeepassertionesacornESnextbrowserslistidleschemehttpvariablesECMAScript 2020protocolumnECMAScript 2018traversepostcssdynamodbcontainsqueueMicrotasktoobjectrfc4122schemaprettyjapaneseemitfantasy-landmetadatasubprocessmapreducemodulesmatchbufferbytezodcurriedclonejsdomlivetypedarraycompile lesssortIteratorvariables in cssloggingprotocol-bufferssuperstructestreeawssymbolwaapivalueRegExp#flagswindowssortedparsingspecWeakSetES2022linkstructuredCloneuninstalles2018privatedeep-cloneArray.prototype.containscryptglacierobjutil.inspectlrucloudsearchdefinePropertyprivate dataroutingcommand-line@@toStringTagES2015Int32Arraylanguageerror-handlingTypeBoxweakmapformatshrinkwrapRFC-6455offsetponyfillauthenticationsimpledbInt16ArrayReactiveXbundlerObjecttoolkittypescriptjson-schema-validatorcloudformationobjectECMAScript 5prototypeautoscalingzxArrayBuffer.prototype.sliceoncees-shimsprogressdescriptionlockfileSystem.globalextramkdirplogirqbundlingasciiwriteclassnamesvpccss nestingdirectorytoolsrfc9562mergefull-widthArray.prototype.filtereslintpluginuuidwhatwgdefinejwtnumbererrorsetio-tsdragnegativeargumentiterateebsrobustdeepcloneoptimizerexpressrouteECMAScript 2016regular-expressionsyntaxerrorformsglobtostringtagsymbolsES5package managerinstallerinputdiffflagspnpm9warningreact animationsqspyyamlnpmignorevaluesbindpredictableECMAScript 2022corehotautoprefixerhelpersopensslclientkeyminimalcryptopreprocessorlintroute53channelnegative zeroArray.prototype.includestoStringTagiefnmatchsharedarraybuffercore-jsBigUint64ArrayswfPushbyteLengthimportxhrstreamseventsencryptiontranspilerhookformes-shim APIglobal objectgetoptreact posefindloadbalancing.gitignoresafecssdataviewcss variablefast-deep-clonetestingES2020s3viewsymlinkamazonlastdropes5executeUint16ArrayslotcollectionsignedES2017ES2023operating-systemhooksassignlistenerssameValueZeroinvariantES2019json-schema-validationcloudtraillesscssvalidatortrimEndes2017chineseUint32ArrayquotedescriptorshasOwnPropertysharednativeloggermrueslint-plugintoReversedfullECMAScript 2021cacheflatpopmotionargscolumnstddfromextendstatelessSymbol.toStringTagprotobufzeroarraybuffersignalnpmcircularvalidateauthfullwidthruntimeprefixentriesflattendirbootstrap cssrdscallboundArrayBuffer#sliceECMAScript 2019colorsimportexportlocalrapidMicrosofttslibclass-validatorpromiseless.jsasyncvisualwalkpostcss-pluginObject.iskeysFunction.prototype.nameflatMapES2016babel-coreArray.prototype.flatlibphonenumberreactfindLastIndextsArrayBufferES2021unicodedependency managerfastifyECMAScript 6clireact-componentreact-hook-formbannershimreact-hooksjshintemrmapfpshelperbeanstalktypanionInt8Arraytakefspropertycjkkinesisnamescss lessinspectgraphqlvalidationexit-codeiamArray.prototype.findLastIndextypesafeterminternal slotfastcopyequalityescapetacitworkflowcloudwatchcheckapolloimmutableregular expressionspawnaccessores2016MapastarraysstablejsquerystringifytrimStartmake dirObject.valuespackage.jsonmkdirmulti-packagestylingbinec2regextelephonejson-schemaAsyncIteratorbyteOffsettoSortedrgbsignalsRxJSconsumebrowserlistJSON-Schemahigher-orderselfstyleguideECMAScript 2017settingsomitpureshellcolourfilterhardlinkses-abstractpatchreduxcreateuploadeslintmkdirsredux-toolkitvarspathansireadableserializationdayjsconfignoperedactignoreless csses6gradients css3readtypemovestringfigletgenericses8intrinsictypesindicatoranimationutilitypreserve-symlinksdomlazyparserfunctionstextFloat64Arrayworkspace:*artES7real-timeincludeswafpasswordSetmanagerjsxcallgetOwnPropertyDescriptorharmonypersistentchromeenumerablebufferscallbindpipecurlPromiseiteratorasterisksassertscall-boundperformancetyped arrayoptioninterruptsttyworkersequencebcryptconcatpropposeHyBiiteration256setterconsoletrimajaxUint8ArrayES6pushenvironmentsreplayhashweaksetowncallbackdependenciesObservableselmstylesheetObject.fromEntriesBigInt64ArrayyupfindLastidentifiersECMAScriptutilscompileragentsymlinksguidproxyregular.envreact-testing-librarypinourldeterministicrequesttrimRightwait
7.11.77

12 months ago

7.11.76

12 months ago

7.10.76

12 months ago

7.10.75

12 months ago

7.10.74

1 year ago

7.10.73

1 year ago

7.10.72

1 year ago

7.10.71

1 year ago

7.10.70

1 year ago

7.10.69

1 year ago

7.10.68

1 year ago

7.10.67

1 year ago

7.10.66

1 year ago

7.10.65

1 year ago

7.10.64

1 year ago

7.10.63

1 year ago

7.10.62

1 year ago

7.10.61

1 year ago

7.10.60

1 year ago

7.10.59

1 year ago

7.10.58

1 year ago

7.10.57

1 year ago

6.10.57

1 year ago

6.10.56

1 year ago

6.9.56

1 year ago

6.9.55

1 year ago

6.9.54

1 year ago

6.9.53

1 year ago

6.9.52

1 year ago

6.9.51

1 year ago

6.9.50

1 year ago

6.9.49

1 year ago

6.9.48

1 year ago

6.9.47

1 year ago

6.9.46

1 year ago

6.9.45

1 year ago

6.9.44

1 year ago

6.9.43

1 year ago

6.9.42

1 year ago

6.9.41

1 year ago

6.9.40

1 year ago

6.9.39

1 year ago

6.9.38

1 year ago

6.8.38

1 year ago

6.8.37

1 year ago

6.8.36

1 year ago

6.8.35

1 year ago

6.8.34

1 year ago

6.8.33

1 year ago

6.8.32

1 year ago

6.8.31

1 year ago

6.8.30

1 year ago

6.8.29

1 year ago

6.7.29

1 year ago

6.7.28

1 year ago

6.7.27

1 year ago

6.7.26

1 year ago

6.6.26

1 year ago

6.6.25

1 year ago

6.6.24

1 year ago

6.6.23

1 year ago

6.6.22

1 year ago

6.6.21

1 year ago

6.6.20

1 year ago

6.6.19

1 year ago

6.6.18

1 year ago

6.6.17

1 year ago

6.5.17

1 year ago

5.5.17

1 year ago

4.5.17

1 year ago

4.5.16

1 year ago

4.5.15

1 year ago

4.4.15

1 year ago

4.4.14

1 year ago

4.4.13

1 year ago

4.4.12

1 year ago

4.4.11

1 year ago

4.4.10

1 year ago

3.4.10

1 year ago

3.3.10

1 year ago

3.2.10

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

2.2.8

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago