About the cookies/localstorage/cache in cobalt - cobalt

It seemed cobalt can support cookies, localstorage, cache, so what's the the max size of cookies for each site? What's the max size of localstorage for each site? What's max size of cache for each site? Is there a total size limit for cookies, for localstorage and for cache separately? Is there a way to set them separately?

Cookies and Local Storage are stored together in an in-memory SQLite database and then serialized and saved into SbStorage. There's a 4MB internal limit on the size of that total storage which isn't currently configurable.
Cache is only used for the splash screen right now, and has no limit enforced by Cobalt.

Related

Redis cache tags flush memory leak

we using Laravel provided Redis tagged cache to cache query results for models in this way:
cache()->tags([model1, model2...])->remember(sql_query_hash, result_callback)
and if in example after some time and a users peak one of tags in example model1 have 500k of unique cached queries, and there comes update and need to do :
cache()>tags([model1])->flush();
my job gets allowed memory exhausted, for workers we have 128MB of memory. Yes I know if I would increase memory of workers I could flush then 1kk of keys etc. but its not a right way because we have exponential users increase and our project will grow, so maybe some of tags will have 10kk of keys on users peak, and how then I have to flush a cache for tag?
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Cache/RedisTaggedCache.php#L174
this is how laravel flush tags keys, by retrieving all in memory then chunks it in memory again so this array_chunk double the memory usage after getting all keys, and then doing Redis::del operation to remove cached keys for this tag.
I don`t know how it call its a bug o not, but for me need some options does anyone dealing with that problem too, and maybe have some solutions?

Cache in multi-tenant environment

I am developing a service that will host multiple tenants. The service will have a limited size cache that will be used by multiple tenants. I do not want to limit the cache size for individual tenants because then we are not effectively using the entire cache pool. But, not having a limit for individual clients might lead to abusing the cache (for example, one tenant may continuously cache the data that will never be retrieved again). What is a better approach?
IMHO, a lot of factors come into picture for this use case. I guess you are using some sorta paid cache model like redis.
A question is how can you restrict size if tenants are not known beforehand. IFA tenant adds up on the fly,you cannot shrink the size of the cache already allowed to the existing tenants
Ideally the cache can be identified based on tenant ID the key. So when you add something to the cache for a tenant, you increase the usage amount on each store.
It would be better to bill the tenant based on the metered cache usage or use a customLRU algorithm to evict the unused cache.
Hope this helps.

Is it normal to have a lot of records in Memached with Laravel?

I have an instance of Laravel up and running with a load balancer in place. We've setup memcached (two server nodes) to handle session management. So far the site is running fine in our test environment. The site largely ties into a web based API, so we only store a few values (other than user authentication data) in a user's session to work with the site.
After a short amount of usage by one or two users, there are about 3000 items in the cache. I don't have full access to the nodes, so I don't know exactly what the items are. However we don't appear to be maxing out the nodes with memory and the application functionality is good.
Is this to be expected? I understand that the cache management will clear out old records over time as they expire, so these could just be "remnant" data records, but this is my first time working with memcached so I want to verify that this is normal behavior.
It's quite normal for any caching solution to rack up a number of items. Especially for lots of small objects it's often more efficient for a cache to keep them beyond their expiry (but no longer serve them) and then clear them out in a big sweep periodically.
"Remnant records" pretty much describes it.
As long as your application performs as expected, I wouldn't worry. You should worry when you get a lot of cache misses for objects that were supposed to be in cache but kicked out before expiry due to lack of memory to store them all.
Yes
It is normal to have lots of records in Memcache. But you need to have proper session management.
Store small amount of values per session. (Data which is required most of the API's, Like user access token)
Cache expiration
The biggest challenge when using Memcache is avoiding cache staleness while still writing clean code. Most developers store data to Memcache and delete or update data when it changes. This strategy can get messy very quickly – Memcache code becomes riddled throughout an application. Rails’ Sweepers can help with this problem, but other languages and frameworks don’t have similar alternatives.
One simple strategy to avoid code complexity is to write data to Memcache with an expiration. Data with an expiration will automatically expire when the expiration is reached. Most applications can benefit from time-based cache expiration with infrequently changing content such as static assets, headers, footers, blog posts, etc.
List management
A simple list stored in Memcache can be useful for maintaining denormalized relationships.
For example An e-commerce website may want to store a small table of recent purchases. Rather than keeping a serialized list in Memcache and recalculating it when a new purchase is made, append and prepend can be used to store denormalized data, avoiding a database query.
Note - Memcache only supports a max value size of 1 MB. Be careful creating lists that may grow larger in size than the maximum allowed value size
Also Check these links-
https://cloud.google.com/appengine/docs/adminconsole/memcache
http://docs.oracle.com/cd/E17952_01/refman-5.6-en/ha-memcached-faq.html
http://symas.com/mdb/memcache/

Best way to update a large set (50K+ keys) of cached (Redis) data during peak load?

Environment: multiple web (30), cache (8) servers and one dedicated database server.
To offload the database, a central Redis cache and local memory cache are in place.
Large common event data is cached and updated based on schedules
User specific data is cached separately when accessed
Problems arise when al large set of user specific data needs is updated due to an event.
There are about 200K of registered users and about 10K-20K come to the site (simultaneously) when the event occurs. With an average of 5 cache keys / user, that’s a total of 50K - 100K cache keys containing user specific data that needs to be updated.
Current solutions fail:
Flushing the user cache overloads the database (30 webservers)
Loading ALL the data into the cache takes a long time (only 10% is used)
KEYS and SCAN can block the cache (not tried yet... is this a problem?)
What is the best practise in this situation?

How to store image as cookie?

Hello
I am working on codeigniter project.
And my question is that : Is it possible to store image as cookie ??
If yes then can please you provide me some documentation or examples on it?
A cookie is a short piece ox text that is stored on the user's computer. Typically it will be no more than 4096 bytes (the lower limit specified by RFC2109). If you can compress and base64 encode an image into this then it might be possible to store an image, but it will be a small image indeed!
There are many ways to tackle the situation,
1.Encode the image to string and store the string to a cookie, but the size limit is 4kb
2.Store the image link to a cookie, but it should either located in our server or the image must be in the internet for locating.
3.Use HTML5 to store images locally HTML5 code example: Intelligently store Images in localStorage for faster page loads!
i have not tried this but i think if you use codeigniter sessions - with a session database table - then you might be able to store the image in the session db table. when you use a session table, codeigniter only stores an ID in the users cookie.
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Resources