Comments (6)
I can suggest:
- Add a
CachedDataReader
decorator for theDataReaderInterface
. A kind of universal caching layerclass CachedReader implements DataReader { private $cache; private DataReader $dataReader ; __construct(DataReader $dataReader) { $this->dataReader = $dataReader; } function read() { // read from $this->dataReader, write to cache; on next call read from cache } }
- We can also add the
CachedDataReader
interface, which will tell us that theDataReader
itself implements the cache - I also liked the idea of adding the
IteratorAggregate
interface to theDataReader
.
Wherein, thegetIterator
method does not write to the cache: realization, documentation
from data.
I suggests:
- By default, be non-cache.
- Extend interface with
snapshot(): self
method. This method would return a reader that, based on the data provided, saves and provide the current data now and in the future.
from data.
@roxblnfk sounds good. @kamarton what do you think?
from data.
@roxblnfk idea is basically like it.
I also liked the idea of adding the IteratorAggregate interface to the DataReader.
Wherein, the getIterator method does not write to the cache: realization, documentation
Ok, if the iterator clearly defines that it represents the current state. I'm thinking here that the iterator can work directly from the data source (eg. fetch partially).
The only problem with this is that count
and read
are not handled together, eg.If the delay is significant (depend on data source change) between the two, the two together are inconsistent.
class CachedReader implements DataReader {
private $cache;
private DataReader $dataReader ;
__construct(DataReader $dataReader) {
$this->dataReader = $dataReader;
}
function read() {
// read count write to cache; on next call read from cache
// read from $this->dataReader, write to cache; on next call read from cache
}
function count() {
// read count write to cache; on next call read from cache
// read from $this->dataReader, write to cache; on next call read from cache
}
}
It is also advisable to assume that the class is already inherited from CachedReader
.
class CachedReader implements DataReader {
private DataReader $dataReader ;
__construct(DataReader $dataReader) {
$this->dataReader = $dataReader;
}
function read() {
if($this->dataReader instanceof CachedReader) {
return $this->dataReader->read();
}
// ...
}
function count() {
if($this->dataReader instanceof CachedReader) {
return $this->dataReader->count();
}
// ...
}
}
from data.
I don't think it should be specified in the interface. In the discussion above about the caching decorator it is clearly visible: one implementation may require caching while another one may not.
from data.
About the cached decorator, I don't see an immediate use-case for it so closing the issue till it's requested for a real use-case.
from data.
Related Issues (20)
- Fix psalm errors HOT 1
- Add `iterable` support in `DataProcessorInterface` HOT 1
- Paginator refactoring concept HOT 2
- Remove `PaginatorInterface` HOT 2
- Increase test coverage to 100%
- Rename filter processor to handler
- Improve namespacing HOT 1
- Move `FilterDataValidationHelper::assertFilterHandlerIsIterable()` method to `Iterable` namespace HOT 2
- Allow pass criteria array to `Group` (reader) filter constructor HOT 1
- Throws exception when pass to `IterableDataReader` non-`IterableFilterHandlerInterface` filter handlers HOT 2
- Make accessing item methods explicit or not? HOT 2
- Add suffix `Handler` for all filter handlers HOT 1
- Finalize `IterableDataReader` HOT 4
- Rename `withFilterHandlers()` to `withAddedFilterHandlers()` into `FilterableDataInterface`
- Remove scrutinizer
- Class Yiisoft\Yii\Cycle\Data\Reader\FilterHandler\AllHandler contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Yiisoft\Data\Reader\FilterHandlerInterface::getFilterClass) HOT 3
- update irc link
- Reuse tests for all data packages
- Add `ILike` filter
- Find a test case with multibyte strings for `Like` and `ILike` filter handlers
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 data.