Comments (5)
They don't belong, as the library does indeed need to enforce its own thread safety via queue confinement.
from tmcache.
Yeah, so I understand the motivation. But is there a specific reason why the code is not thread safe by default? It seems relatively trivial to make the in-memory cache operations atomic and the disk reading should be thread safe since NSFileManager is thread safe?
Is it just to make the code easier to write?
from tmcache.
Thanks for your help btw.
from tmcache.
The asynchronous methods are the "real" methods, the synchronous methods are just convenient sugar to make your code cleaner when you need to wait on a response. Everything has to happen on the queue to keep the cache consistent and prevent contention.
However, in practice you'll rarely need to wait on the queue. Reads are concurrent and extremely fast, and the queue is only blocked when there's a write.
If you're not concerned with thread safety you might be better off with vanilla NSDictionary and the file manager. Otherwise, coalescing responses would be a great job for dispatch_group()
from tmcache.
Haha. I'm definitely concerned with thread safety...I just was thinking that usually I expect serial methods to give control over the threading to the caller.
However, I think I was wrong to think this was a good idea for a few reasons:
- TMCache seems to be as parallel as possible while retaining consistency.
- I was worried that there would be a performance hit by lots of dispatch_async calls (spinning up threads is expensive). Turns out this was misguided as dispatch_async does not create a new thread every time you call it but runs off a shared thread pool (from my understanding).
- The threading is more complex that I imagined, and as a caller I shouldn't assume that I can do it correctly.
Anyway, most of this question was motivated by wanting to do batch requests quickly. I could see how the library may be able to handle batch requests in just 'one request'. As in, it doesn't need to dispatch_group and submits less blocks to GCD. The library could also expose an API method that did the grouping logic for the caller for convenience.
However, from what I've read above, this doesn't seem necessary for now. I'll test it out with my use case, and if I find any performance problems that could be solved by smarter batching, I'll open another issue to discuss. I doubt that will be the case though.
Since my question was answered, I'll close the issue for now.
Thanks.
from tmcache.
Related Issues (20)
- cache life time HOT 4
- Update changelog HOT 2
- NSInternalInconsistencyException
- question about cost limit HOT 3
- Completion block is not called HOT 2
- [email protected]
- ageLimit is not an ageLimit
- "byteCount" get the wrong value after caching multiple times on the same key HOT 4
- disscuss about thread safe HOT 3
- No changelog for 2.0? HOT 2
- [Question] MemoryWarning in 2.0 HOT 11
- Memory warning block did not execute
- Advice on usage for offline solution HOT 3
- TMDiskCache's enumerateObjectsWithBlock doesn't return objects HOT 1
- setObject not working
- setObject generates .dat.nosync instead of normal cache file in the path. HOT 2
- 你好
- investigate TMCache update
- crash in NSKeyedUnarchiver unarchiveObjectWithFile HOT 2
- 死锁问题有人在看么
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tmcache.