Comments (8)
@angelxmoreno
The Mapper
class includes already an identity map:
But the question is: why do you think a cache is needed?
from atlas.orm.
@angelxmoreno I opine that the place for caching is in your domain layer repositories, not your persistence layer mappers. That is, cache your domain objects, not your persistence objects.
Now, having said that, I presume that your motivation for caching is a performance issue of some sort. Is that the case? If so, are you able to describe it here?
from atlas.orm.
I think it's better to use third-party caching library that can cache objects.
from atlas.orm.
@gugglegum I attempted to use symfony cache and added a trait on my MapperSelect
exposing a fetchCachedRecordSet
. I then went ahead and added a \Serializable
implementation on my RecordSet
in order for the cache engine to safely serialize the RecordSet object. I ran into many issues in implementing a way to create a RecordSet from an array of values. However i ran into issues when attempting to create the RecordSet when it contained associated data ( relationship data).
This is mainly the reason why I asked the question. To see if there is a known and working solution before I dug deeper.
@froschdesign ty for pointing that out. That seems to be memoizing the objects but what I am looking for is a solution for storing data for a few minutes.
Looking at the identityMap property does shed light on a few things given my previous failed implementation. Ty for highlighting this.
It would be great if we had some documentation on how to implement some type of cached queries implementation. If I am successful I can write something but that is going to take me a little time.
from atlas.orm.
...what I am looking for is a solution for storing data for a few minutes.
Why do you need this? Do you have performance problems or something else?
from atlas.orm.
I am working on CLI scripts that generate reports based on a massive mysql db. The various reports paginate through a few million rows of data to generate these reports. I would like to increase the performance of the CLI scripts by caching frequently made sql calls.
from atlas.orm.
@angelxmoreno I don't think you need to go this way. In pagination you're fetching different data every time. So if you will cache them, you will get performance only on the next report generation. But in this case your reports may be outdated. Also, take a notice that if data is changing while you paginate it, the data in pages can be shifted. So some records can be fetched twice or some missed. Usually, when you making a report, you don't need to fetch whole database into your script, you need to use some JOINS and GROUP BY clauses to allow MySQL to prepare needle data for you. And even if you relally need to fetch and iterate big amount of data in your script, it's better to not use pagination. Use yield*
methods which do not load all results into PHP memory at once. Or even try to use unbuffered query (you may need 2 parallel MySQL connections to make additional queries while you iterate results from unbuffered query). This trick allow you to fetch from MySQL really huge amount of data with very low memory consumption in PHP. Also, optimize your queries, use "DESCRIBE SELECT" syntax to see which query conditions works without indexes ("using filesort"). Optimized big queries may work not very slower than cache.
from atlas.orm.
ty
from atlas.orm.
Related Issues (20)
- The name of the static method 'new' in the Atlas class seems to generate a parse error in third party libraries like phpDocumentor HOT 14
- joinWith doesn't work when specifying direction
- On updates, 1 and true and not being treated as the same for bit/boolean columns and values HOT 1
- Cannot delete all records in a many-to-many HOT 4
- Wrong parameters for PDOException? HOT 1
- Updating Many to Many?
- Postgres: problem when using uuid type field HOT 3
- Question: how to use raw insert values in ORM HOT 3
- Support for read-only MySQL generated columns
- Help: how to use advanced ORM feature HOT 5
- Help: Only the first result in a select includes data from related records HOT 7
- [Help Required] Getting Atlas\Mapper\Exception when trying to fetch a record from SQLite HOT 3
- How to use PHP-DI PSR 11 and Repository HOT 1
- Question: Where is the best place to convert php values to database values? HOT 6
- Row name for Exception::rowNotMapped() and Exception::rowAlreadyMapped() HOT 1
- orderBy missing HOT 1
- Issue with character encoding HOT 12
- Relationships manyToOne NULL HOT 8
- Missing get PDO connection from Atlas ORM 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 atlas.orm.