PHPackages                             tasoft/cached-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. tasoft/cached-generator

ActiveLibrary[Caching](/categories/caching)

tasoft/cached-generator
=======================

v0.9.10(3y ago)01011MITPHPPHP &gt;=7.2CI failing

Since Oct 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tasoftch/php-cached-generator)[ Packagist](https://packagist.org/packages/tasoft/cached-generator)[ RSS](/packages/tasoft-cached-generator/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

Cached Generator
================

[](#cached-generator)

#### Issue

[](#issue)

A generator is a forward only iterator.
Fetching resources from a file or database or wherever consumes performance. There I love to use generators to only load what is really required.

```
I want to load a user with the username "admin"
Of course using MySQL you can create a specific request.
But If you do not know the sources, you need to iterate over all users and check, if one matches to the username.
With common iterators PHP will load all users first and then you have the possibility to pick the right one.
Using generators you may load user by user and check. If found, stop iteration.

```

But what if you want again to look for a user?
You can not rewind a generator.

```
