0

I need to store some cache of objects with data. How can I to compress them when put to cache and uncompress when read from it?

I need to cache some pages of store in my client-side logic for my purposes. I think I can have a lot of data, so when records count will be much than 500, I'll clear older values. My cache is just an JavaScript Object, so I need to store all data (which is array of objects) in memory.

As Oleg Volkov said (привет!), I describe my task:

1) there is some ExtJS 4.1 store and combo with multiSelect and pagination

2) I wrote some functional (client and server sides both) which can a) to get page when value I want to set is placed) b) can to setValues values in way they will be stored in foundedValues object to save their values (to set within setRawValue) and can to highlight them when i moving across pages.

3) My pageSize is 25. So, if I want to do setValues([1, 34, 10]), store will get value from firstPage, then load second, get value (34), and will go to first to get 10! But I want to store that all values from 1 to 25 are belongs to first page, and get it from cache, not within Ajax requests.

Guy Fawkes
  • 2,313
  • 2
  • 22
  • 39
  • Use an (un)compressor algorithm? Or event better, let the browser do the work for you. – Bergi Jun 08 '12 at 13:22
  • which algorithms can I to use? Do you know some good implementations in js? – Guy Fawkes Jun 08 '12 at 13:23
  • Let the browser do it? How does that work? You can GZIP it for transfer from the server, but how would that work for local storage? – Diodeus - James MacFarlane Jun 08 '12 at 13:26
  • 3
    The real question is: why do you *need* to compress your data? If you feel the need of it, you're probably dealing with *too much data* for an efficient client-side scripting in the first place. – MaxArt Jun 08 '12 at 13:26
  • 2
    Where are you caching the data? – kiranvj Jun 08 '12 at 13:28
  • I answered this questions in my post. – Guy Fawkes Jun 08 '12 at 13:54
  • @GuyFawkes: Compressor algorithms always depend on the type of data to deal with. And yes, when the browser caches that data it will compress it, of course. – Bergi Jun 08 '12 at 13:56
  • I don't need data caching in way how browser does it. I need to store some arrays of objects in memory. – Guy Fawkes Jun 08 '12 at 13:57
  • >> I need to store some arrays of objects in memory - THis was what I was asking and its not mentioned in the question like u said. There are different caching locations other than memory, thats why I asked. – kiranvj Jun 08 '12 at 13:59
  • I'm sorry, I'll add it to question. Why my question is voted down? My way is bad? – Guy Fawkes Jun 08 '12 at 14:02
  • Upvoted. >>My way is bad? ->I didnt find this reply correct -> I answered this questions in my post. – kiranvj Jun 08 '12 at 14:04
  • You don't "need to store some cache". You need to do some other task, which *YOU ASSUME*, should be done with some cache. Post your task instead if you want meaningful and useful answers. – Oleg V. Volkov Jun 08 '12 at 14:09

2 Answers2

2

You should not do this, quite apart from the considerable effort in space (code) and time (CPU) it would take. Systems where space is at a premium (mobile?) also have only limited CPU power (and it costs ENERGY to compress stuff!), so if you need it you should not do it anyway.

Client-side code (today) should keep the bulk of data - if it is a lot - on the server, and only ask for small chunks on demand. The browser's JS engine may or may not do its own compression, that really is not your business as JS programmer. Same as memory management, which is deliberately kept away from the hands of the JS programmer.

So the answer is: redesign your app to follow the current programming paradigm for JS client/server programming and interaction.

Mörre
  • 5,699
  • 6
  • 38
  • 63
1

The effort you put in client side to compress and decompress the data is not worth making the data size smaller in memory.

Still if yo need to do compression check these links.

  1. -
  2. JavaScript implementation of Gzip
  3. Can I compress data in JavaScript?
  4. http://forums.devshed.com/javascript-development-115/compress-strings-arrays-263804.html
Community
  • 1
  • 1
kiranvj
  • 32,342
  • 7
  • 71
  • 76