Answers.Body: <p>There isn't really a good way to extract large chunks of Craft entries using the core features in Twig. Every entry you fetch is a <code>EntryModel</code> and those take up some memory due to relations and other stuff in Yii's ActiveRecord class.</p>
  
  <p>What you can do is to create your own custom Plugin that does the same thing but queries the database directly instead, by-passing Crafts <code>EntryModels</code> and just giving you the dataset results directly.</p>
  
  <p>Here's some resources on getting started with Plugin development:</p>
  
  <p>Craft official documentation: <a href="https://craftcms.com/docs/plugins/introduction">https://craftcms.com/docs/plugins/introduction</a></p>
  
  <p>From StraightUpCraft: <a href="https://straightupcraft.com/plugin-development">https://straightupcraft.com/plugin-development</a></p>
  
  <p>A wrapper for creating a Plugin default setup: <a href="http://pluginfactory.io/">http://pluginfactory.io/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-21T18:57:22.017Z
Answers.Text: The concept helped me with a project in 2022, Thanks 
Answers.UserDisplayName: Ra3d K
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-15T16:10:09.960Z
Answers.LastActivityDate: 2016-03-15T16:10:09.960Z
Answers.UserDisplayName: naboovalley
Body: <p>Ok, so I'm looping through a lot of entries. It's a large request, and I had to up php memory limit to 512M. But I'm sure there is a less memory consuming way to do this. Also, I want to cache the whole thing, apparently 512M isn't enough for that.</p>
  
  <p>Any suggestions? Should I just go ahead and use the ElementAPI?</p>
  
  <pre><code>var geojson = [
            {
              "type": "StationCollection",
              "features": [
              {% for entry in craft.entries.section('map').limit(3000).find() %}
                  {
                  "type": "Feature",
                  "geometry": {
                    "type": "Point",
                    "coordinates": [
                      {{entry.address.lng}},
                      {{entry.address.lat}}
                    ]
                  },
                  "properties": {
                    "title": "{{entry.title}}",
                    "slug": "{{entry.slug}}",
                    "alwaysOpen": "{{entry.alwaysOpen}}",
                    "phone": "{{entry.phone}}",
                    "saturdays": "{{entry.saturdays}}",
                    "stationType": "{{entry.stationType}}",
                    "sundays": "{{entry.sundays}}",
                    "workingDays": "{{entry.workingDays}}",
  
                  }
                },
              {% endfor %}
          ]
        }
      ];
  </code></pre>
  
Tags: <cache><forloop><performance><json>
Title: Looping out a lot of entries.
ThreadText: # Looping out a lot of entries.
  
  (Asked by: username_0 on 2016-03-15)
  
  Ok, so I'm looping through a lot of entries. It's a large request, and I had to up php memory limit to 512M. But I'm sure there is a less memory consuming way to do this. Also, I want to cache the whole thing, apparently 512M isn't enough for that.
  
  Any suggestions? Should I just go ahead and use the ElementAPI?
  
  ```
  var geojson = [
            {
              "type": "StationCollection",
              "features": [
              {% for entry in craft.entries.section('map').limit(3000).find() %}
                  {
                  "type": "Feature",
                  "geometry": {
                    "type": "Point",
                    "coordinates": [
                      {{entry.address.lng}},
                      {{entry.address.lat}}
                    ]
                  },
                  "properties": {
                    "title": "{{entry.title}}",
                    "slug": "{{entry.slug}}",
                    "alwaysOpen": "{{entry.alwaysOpen}}",
                    "phone": "{{entry.phone}}",
                    "saturdays": "{{entry.saturdays}}",
                    "stationType": "{{entry.stationType}}",
                    "sundays": "{{entry.sundays}}",
                    "workingDays": "{{entry.workingDays}}",
  
                  }
                },
              {% endfor %}
          ]
        }
      ];
  
  ```
  
  **Tags:** cache, forloop, performance, json
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-15. Score: 4 | Accepted answer
  
  There isn't really a good way to extract large chunks of Craft entries using the core features in Twig. Every entry you fetch is a `EntryModel` and those take up some memory due to relations and other stuff in Yii's ActiveRecord class.
  
  What you can do is to create your own custom Plugin that does the same thing but queries the database directly instead, by-passing Crafts `EntryModels` and just giving you the dataset results directly.
  
  Here's some resources on getting started with Plugin development:
  
  Craft official documentation: <https://craftcms.com/docs/plugins/introduction>
  
  From StraightUpCraft: <https://straightupcraft.com/plugin-development>
  
  A wrapper for creating a Plugin default setup: <http://pluginfactory.io/>
  
  > **Comments:**
  > **username_2**: The concept helped me with a project in 2022, Thanks   
  
  ---
  
  