javascript - How do I create a variable that persists across reloads and code pushes? -


if write plugin requires large initialization (14 mb javascript takes 1 minute set up), how can make object persistent (for lack of better word) across javascript files used in meteor projects?

after initialization of plugin, have object largeobject , when add file simple_todo.js, want use largeobject without taking minute load after every change.

i cannot find solution.

i tried making separate package store in package object, cleared after every change , reinitialized.

what proper way of doing that? imagine there should internal in meteor survives hot code push.

here 2 possible solutions i:

  • cache of properties inside session
  • cache of properties inside simple collection
  • use stub in local environment.

session can used client side. can use collection anywhere.

session

client

example = function () {   if(!(this.alotofdata = session.get('alotofdata'))) {     this.alotofdata = computealotofdata()     session.set('alotofdata', this.alotofdata)   } } 

here, no data has transferred between client , server. every new client connects, code rerun.

collection

lib

muchdatacollection = new mongo.collection('muchdatacollection') 

server

meteor.publish('muchdata', function (query) {   return muchdatacollection.find(query) }) 

server

example = function () {   if(     !this.alotofdata = muchdatacollection.findone({       name: 'alotofdata'     }).data   ) {     this.alotofdata = computealotofdata()     muchdatacollection.insert({       name: 'alotofdata',       data: this.alotofdata     })   } } 

even dough can access collection anywhere, don't want able make changes it. because clients share same collection. collections cached client side. read this more info.

stub

a stub easiest implement. it's worst solution. you'll have use settings variable , still end having code stub inside production environment.

what choose

it depends on exact use-case. if contents of object depend on client or user, it's best use session-var. if doesn't go collection. you'll need build cache-invalidation mechanisms, i'd say, it's worth it.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -